In Material UI, How can I override a selector selected component style?

半城伤御伤魂 提交于 2020-01-03 04:01:07

问题


In Material UI, to extend the distance between MuiInputLabel and MuiInput, I have to override the marginTop of label + .MuiInput-formControl.

However, createMuiTheme's override only provide direct override of a Mui Component CSS, such as:

createMuiTheme({
  overrides: {
    MuiInput: {
      formControl: {
        marginTop: '1.5rem',
      },
    },
  }
})

How can I do something like:

createMuiTheme({
  overrides: {
    'label+MuiInput': {
      formControl: {
        marginTop: '1.5rem',
      },
    },
  }
})

Thanks...


回答1:


Here's the relevant JSS documentation:

https://cssinjs.org/jss-plugin-nested?v=v10.0.0-alpha.10#use--to-reference-selector-of-the-parent-rule

Here's the syntax you need:

const theme = createMuiTheme({
  overrides: {
    MuiInput: {
      formControl: {
        "label + &": {
          marginTop: "1.5rem"
        }
      }
    }
  }
});

Here's a working example:



来源:https://stackoverflow.com/questions/54724968/in-material-ui-how-can-i-override-a-selector-selected-component-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!