【问题标题】:How to change the underline and label color of Material-UI <Select/>Material-UI <Select/>如何改变下划线和标签颜色
【发布时间】:2020-07-10 10:39:42
【问题描述】:
【问题讨论】:
标签:
javascript
css
reactjs
material-ui
【解决方案1】:
用<FormControl /> 包装您的选择,并将<InputLabel /> 添加为<Select /> 同级。
之后,覆盖 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>
);
}