【问题标题】:How to change the underline and label color of Material-UI <Select/>Material-UI <Select/>如何改变下划线和标签颜色
【发布时间】:2020-07-10 10:39:42
【问题描述】:

我用这个演示改变了一些输入字段的颜色:https://stackblitz.com/edit/material-ui-custom-outline-color

我想知道当他们从材质 UI 更改选择组件的颜色时,是否有人有类似的演示?或者一些关于如何去做的说明(我已经查看了文档,但正在努力遵循它们)。

谢谢!

【问题讨论】:

标签: javascript css reactjs material-ui


【解决方案1】:

用&lt;FormControl /&gt; 包装您的选择,并将&lt;InputLabel /&gt; 添加为&lt;Select /&gt; 同级。
之后,覆盖 InputLabel 根类并提供 className 来选择组件:

const useStyles = makeStyles((theme) => ({
  formControl: {
    margin: theme.spacing(1),
    minWidth: 120,
  },
  underline: {
    color: 'red' ,
    '&::after': {
      borderBottom: '2px solid red'
    },
    '&::before': {
      borderBottom: '2px solid yellow'
    }
  },
  inputLabelRoot: {
    color: 'red',
  }
}));

export default function SimpleSelect() {
  const classes = useStyles();

  return (
    <div>
      <FormControl className={classes.formControl}>
        <InputLabel classes={{root: classes.inputLabelRoot}}>Age</InputLabel>
        <Select
          className={classes.underline}
        >
          <MenuItem value={10}>Ten</MenuItem>
          <MenuItem value={20}>Twenty</MenuItem>
          <MenuItem value={30}>Thirty</MenuItem>
        </Select>
      </FormControl>
    </div>
  );
}

【讨论】:

    猜你喜欢
    • 2019-07-28
    • 2019-11-10
    • 1970-01-01
    • 2018-11-16
    • 2018-07-06
    • 2019-02-10
    • 2021-05-28
    • 1970-01-01
    • 2020-07-08
    相关资源
    最近更新 更多