如何使用辅助调色板颜色更改对话框内文本字段的下划线颜色?我不能这样做,因为文档很混乱
材料 ui 下一个对话框文本字段下划线颜色
IT技术
reactjs
material-ui
2021-04-27 21:49:31
2个回答
假设您使用的是 material-ui-next,您可以在createMuiTheme 中使用覆盖。
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
const theme = createMuiTheme({
overrides: {
MuiInput: {
underline: {
'&:before': { //underline color when textfield is inactive
backgroundColor: 'red',
},
'&:hover:not($disabled):before': { //underline color when hovered
backgroundColor: 'green',
},
}
}
}
});
然后用MuiThemeProvider包装你的应用程序
ReactDOM.render(
<MuiThemeProvider theme={theme}>
<Root />
</MuiThemeProvider>,
document.getElementById('root')
);
它将覆盖所有 TextField material-ui 组件的下划线颜色。如果您只需要为一个 TextField 更改颜色,请使用https://material-ui-next.com/customization/overrides/#1-specific-variation-for-a-one-time-situation
Rinat 的回答似乎不适用于当前版本 v16.13.1。使用borderBottom
而不是backgroundColor
.
(借用他的回答使答案更清晰,希望我没有违反任何 SO 准则)
import { createMuiTheme } from "@material-ui/core/styles";
const theme = createMuiTheme({
overrides: {
MuiInput: {
underline: {
'&:before': { //underline color when textfield is inactive
borderBottom: `1px solid ${"red"}`,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
},
'&:hover:not($disabled):before': { //underline color when hovered
borderBottom: `2px solid ${"red"}`,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
},
}
}
}
并像以前一样用 MuiThemeProvider 包装它:
import { ThemeProvider } from "@material-ui/styles";
ReactDOM.render(
<MuiThemeProvider theme={theme}>
<Root />
</MuiThemeProvider>,
document.getElementById('root')
);