【问题标题】:How to override styles for material-ui TextField component without using the MUIThemeProvider?如何在不使用 MUIThemeProvider 的情况下覆盖 material-ui TextField 组件的样式?
【发布时间】:2018-10-30 09:12:52
【问题描述】:

如何使用以下代码隐藏/删除 TextField 组件中的下划线不使用

const theme = createMuiTheme({
  overrides: {
    MuiInput: {
      underline: {
        '&:hover:not($disabled):before': {
          backgroundColor: 'rgba(0, 188, 212, 0.7)',
        },
      },
    },
  },
});

我想使用道具并根据文档:https://material-ui.com/api/input/

我应该可以更改下划线道具,但它不起作用。

【问题讨论】:

    标签: reactjs material-ui jss


    【解决方案1】:

    这就是你的做法:

    <TextField
        id="name"
        label="Name"
        value={this.state.name}
        margin="normal"
        InputProps={{disableUnderline: true}}
    />
    

    我是怎么知道的?

    您已链接到Input documentation,它确实有一个disableUnderline 属性。

    但是,您使用的是TextField component

    了解文本字段很简单很重要 在以下组件之上的抽象:

    • 表单控件
    • 输入标签
    • 输入
    • FormHelperText

    如果您查看TextField 的可用道具列表:

    InputProps - 对象 - 应用于 Input 元素的属性。

    【讨论】:

    • 嘿伙计。是的,我已经想通了。无论如何感谢您的帮助!
    • 当我使用 inputProps 时,自动完成免费独奏的建议消失了。
    【解决方案2】:

    我找到了解决此问题的方法..

    <TextField InputProps={{classes: {underline: classes.underline}}} />
    
    const styles = theme => ({
      underline: {
        '&:hover': {
          '&:before': {
            borderBottom: ['rgba(0, 188, 212, 0.7)', '!important'],
          }
        },
        '&:before': {
          borderBottom: 'rgba(0, 188, 212, 0.7)',
        }
      }
    })
    

    【讨论】:

      【解决方案3】:

      使用最新版本的 Material-UI,这是我完成这项工作的唯一方法:

      <TextField InputProps={{classes: {underline: classes.underline}}} />
      
      const styles = theme => ({
        underline: {
          '&:before': {
            borderBottomColor: colors.white,
          },
          '&:after': {
            borderBottomColor: colors.white,
          },
          '&:hover:before': {
            borderBottomColor: [colors.white, '!important'],
          },
        },
      })
      

      【讨论】:

        猜你喜欢
        • 2019-07-20
        • 2019-05-31
        • 2021-09-15
        • 2020-04-13
        • 2013-02-06
        • 2019-10-02
        • 2020-01-30
        • 2019-03-07
        • 2020-03-20
        相关资源
        最近更新 更多