material-ui-pickers: MUI throws warning about theme override for selected state
Environment
| Tech | Version |
|---|---|
| material-ui-pickers | 2.0.5 |
| material-ui | 3.8.1 |
| React | 16.7.0 |
| Browser | any |
| Peer library | date-fns |
Steps to reproduce
- Add theme override for
MuiPickersDay.selected - Load a page with date picker on it
Expected behavior
No MUI warnings
Actual behavior
Material UI throws a warning:
Warning: Material-UI: the `MuiPickersDay` component increases the CSS specificity of the `selected` internal state.
You can not override it like this:
{
"selected": {
"backgroundColor": "#002d52",
"color": "#fff",
"&:hover": {
"backgroundColor": "#003B64"
}
} ...
}
Instead, you need to use the $ruleName syntax:
{
"&$selected": {
"backgroundColor": "#002d52",
"color": "#fff",
"&:hover": {
"backgroundColor": "#003B64"
}
}
}
https://material-ui.com/customization/overrides#internal-states
The code for this warning was introduced here:
https://github.com/mui-org/material-ui/pull/13919
It seems there are conventions around the specific keys 'disabled', 'focused', 'selected', 'checked'
Live example
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (1 by maintainers)
The MuiListItem Component is a Component of the @material-ui/core package and isnt in any relation with this project. But never mind - I can help you 😃
Just do something link this in your theme:
Please check my codesandbox, it shows the cause of the error and commented out the way to fix it:
@RobelTekle it worked for me after wasting few hours thanks.
@janhoeck I still have some issues with your solution, I receive a warning message
Warning: Material-UI: you are trying to override a style that does not exist. Fix the 'root' key of theme.overrides.MuiPickersDay.and the app crash becauseUncaught TypeError: Cannot read property '&$selected' of undefinedThanks, I was missing root prop there