Material-ui: MenuItem: add ability to style disabled

Created on 1 Feb 2019  路  8Comments  路  Source: mui-org/material-ui

  • [x] This is not a v0.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃


We should be able to override disabled MenuItems like so:

createMuiTheme({
    overrides: {
      MuiMenuItem: {
        disabled: {
          color: 'blue',
        },
      },
    },
  });

Or, following the new syntax:

createMuiTheme({
    overrides: {
      MuiMenuItem: {
        root: {
          '&$disabled': {
            color: 'blue',
          },
        },
      },
    },
  });

Current Behavior 馃槸


The only way to override the styles for a disabled MenuItem is by overriding ListItem styles:

createMuiTheme({
    overrides: {
      MuiListItem: {
        disabled: {
          color: 'blue',
        },
      },
    },
  });

Examples 馃寛

Context 馃敠


We want to style disabled ListItems and disabled MenuItems differently.

Menu enhancement

All 8 comments

We want to style disabled ListItems and disabled MenuItems differently.

@tpeek You can create a wrapper. Something like this:

import { styled } from '@material-ui/styles';
import MuiMenuItem from '@material-ui/core/MenuItem';

const MenuItem = styled(MuiMenuItem)({
  color: props => props.disabled ? 'blue' : 'red',
});

export default MenuItem;

You can create a wrapper. ...

We try to keep all the style changes in the overrides, that way we can use the ThemeProvider and Material-UI components directly. It鈥檚 much more convenient than adding custom logic every time or remembering which components you need to import from locally or from Material-UI.

We try to keep all the style changes in the overrides

@tpeek For a limited number of overrides it's fine:

const theme = createMuiTheme({
  overrides: {
    MuiMenuItem: {
      root: {
        color: props => (props.disabled ? "blue" : "red")
      }
    }
  },
});

https://codesandbox.io/s/y6j72775x

Awesome, that will work for our use case. Thank you!

I think it would still be nice to add the ability to style it as I suggested above, to match the api of many other components that you can style via overrides when disabled, without needing to access props.

I think it would still be nice to add the ability to style it as I suggested above

@tpeek I have no objection with that.

For a limited number of overrides it's fine: ...

By this, do you mean that we shouldn't overuse this feature for performance reasons, or does this only work in certain overrides?

@tpeek The theme is a singleton, you can't leverage code splitting.

Another possible solution: the .Mui-disabled pseudo-class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damianobarbati picture damianobarbati  路  55Comments

iceafish picture iceafish  路  62Comments

garygrubb picture garygrubb  路  57Comments

chadobado picture chadobado  路  119Comments

NonameSLdev picture NonameSLdev  路  56Comments