4
votes

I'm using the Material-ui-next Select component in a project.

Most of the styles are being overriden using the classes prop. But the selected key can't get to work even using MuiThemeProvider.

Here is the relevant parts of the code:

...

const theme = createMuiTheme({
  overrides: {
    MuiMenuItem: {
      selected: {
        backgroundColor: 'transparent',
      }
    }
  }
});

...

class SelectMUI extends Component {

  render() {

  const {className, name} = this.props

  return (
    <MuiThemeProvider theme={theme}>
      <Select
        classes={{root: 'muisc-root', icon: 'muisc-icon', select: 'muisc-select', selectMenu: 'muisc-select-menu'}}
        className={`mui-select-custom ${className}`}
        endAdornment={<Caret className='mui-select-caret'/>}
        MenuProps={{classes: {paper: 'muisc-menu-paper'}}}
        {...this.props}
      >
        {this.props.children}
      </Select>
  </MuiThemeProvider>
)

} }

So, as you can see, while I'm importing the MenuItems as props, I'm using the MuiThemeProvider to inject style in the items.

And here is a screenshot of the applied style in a selected item:

enter image description here

How to override this selector that is combining two classes from the same element?

1
Have you tried using important? backgroundColor: 'transparent !important'nbkhope
I can't use !important because someone else will style it using sass. If i was the person, I would use !important even in the css file, but I can't count on it.Daniel Miclos

1 Answers

11
votes

ok, I figure it out how to override a combined selector. Here is the solution:

   MuiMenuItem: {
      root: {
        background: 'transparent',
        '&$selected': { // <-- mixing the two classes
          backgroundColor: 'transparent'
        }
      }
    }