首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改<DatePicker />组件的颜色?

如何更改<DatePicker />组件的颜色?
EN

Stack Overflow用户
提问于 2021-06-23 06:00:39
回答 1查看 372关注 0票数 1

我想更改DatePicker组件的下划线颜色。以下是我这样做的尝试

代码语言:javascript
复制
import React from 'react'
import PropTypes from 'prop-types'
import { DatePicker as MuiDatePicker, MuiPickersUtilsProvider } from '@material-ui/pickers'
import { makeStyles } from '@material-ui/core/styles'
import DateFnsUtils from '@date-io/moment' // choose your lib
import { usePreset } from '../'

const presets = {
    repainted: {
        InputProps: {
            className: 'test',
            underColor: 'yellow',
            style: {
                color: 'red',
                borderBottomColor: 'red',
                '&::before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                '&input::before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                '&input:before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                'input::before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                'input:before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                '&:before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                '&&:before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                '&&::before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                '::before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
                ':before': {  // attemp
                    color: 'yellow',
                    borderBottomColor: 'yellow',
                    background: 'yellow',
                },
            },
        },
        useStyles: makeStyles(theme => ({
            root: {},
        })),
    },
}

const DatePicker = React.forwardRef((props, ref) => {
    const {classes, ...rest} = usePreset(presets, props)

    return (
        <MuiPickersUtilsProvider utils={DateFnsUtils}>
            <MuiDatePicker ref={ref} className={classes?.root} {...rest}/>
        </MuiPickersUtilsProvider>
    )
})

DatePicker.propTypes = {
    preset: PropTypes.oneOf(Object.keys(presets)),
    ...MuiDatePicker.propTypes,
}

export default DatePicker

这是组件。请注意,当我看到文本颜色的变化时,组件会收到正确的预置。

EN

回答 1

Stack Overflow用户

发布于 2021-07-05 11:22:40

根据文档,The only way to override existing stylesheets are with the use of global material-ui theme overrides.。您还可以尝试使用内联样式来更改组件的颜色。来源:https://material-ui-pickers.dev/guides/css-overrides

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68094293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档