小编Yuk*_*hka的帖子

使用 styed-components 和 Material-UI withStyles 的 TextField 样式

这是TextField使用withStylesMaterial-UI 本身的Material-UI样式:

export const STextField = withStyles({
  root: {
    background: 'white',
    '& label.Mui-focused': {
      color: 'white'
    },
    '& .MuiInput-underline:after': {
      borderBottomColor: 'white'
    },
    '& .MuiOutlinedInput-root': {
      '& fieldset': {
        borderColor: 'white'
      },
      '&:hover fieldset': {
        borderColor: 'white'
      },
      '&.Mui-focused fieldset': {
        borderColor: 'white'
      }
    }
  }
})(TextField);
Run Code Online (Sandbox Code Playgroud)

它完美无缺。

有什么办法可以使用相同的样式styled-components吗?

我试过这个:

export const STextField = styled(TextField)`
.MuiTextField-root {
  background: 'white'
    & label.Mui-focused: {
      color: 'white'
    },
    & .MuiInput-underline:after: {
      borderBottomColor: 'white'
    },
    & .MuiOutlinedInput-root: { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui styled-components

2
推荐指数
1
解决办法
667
查看次数