材料ui下一个对话框textfield下划线颜色

Ale*_*uez 3 reactjs material-ui

如何使用辅助调色板颜色更改对话框内文本字段的下划线颜色?我不能这样做,因为文档很混乱

小智 8

假设您正在使用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',
        },
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

});

然后用MuiThemeProvider包装你的应用程序

ReactDOM.render(
 <MuiThemeProvider theme={theme}>
   <Root />
 </MuiThemeProvider>,
 document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)

它将覆盖所有TextField material-ui组件的下划线颜色.如果您只需要为一个TextField更改颜色,请使用https://material-ui-next.com/customization/overrides/#1-specific-variation-for-a-one-time-situation