【问题标题】:Material UI TextField customizationMaterial UI TextField 自定义
【发布时间】:2019-08-30 17:58:32
【问题描述】:

我不能在 TextField 组件中自定义标签。样式不适用于TextField 组件中的标签。我做错了什么?

    import React, { PureComponent } from 'react'
    import { withStyles } from '@material-ui/core/styles'
    import TextField from '@material-ui/core/TextField'

    const StyledTextField = withStyles({
        root: {},
        label: {
            textTransform: 'uppercase'
        }
    })(TextField)

    class App extends PureComponent {
        render() {
            return (
                <StyledTextField
                    id='city-of-residence'
                    label='Город проживания'
                    fullWidth={true}
                    margin='normal'
                    helperText='helperText'/>
            )
        }
    }

    ReactDOM.render(<App />, document.getElementById('root'))

预期结果 =)

当前结果 =(

【问题讨论】:

    标签: reactjs material-ui customization textfield


    【解决方案1】:

    您好,您可以在标签内使用您的自定义反应元素,如下所示

     <StyledTextField
                        id='city-of-residence'
                        label={<p style={{textTransform: 'uppercase'}}>Город проживания</p>}
                        fullWidth={true}
                        margin='normal'
                        helperText='helperText'/>
                )
    
    

    【讨论】:

    • 是的,现在我也在做类似的事情:InputLabelProps={{style: {textTransform: 'uppercase'}}}
    • 但这是通往黑暗面的道路
    • @north.inhale 什么是光明的一面?
    【解决方案2】:

    可以在css中使用text-transform: uppercase;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-27
      • 2020-07-18
      • 2020-06-29
      • 1970-01-01
      • 2021-10-03
      • 2023-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多