[ListItem] Custom background color always has overridden by MUI style
See original GitHub issueWhen I’m trying override background color of root node for ListItem( the attribute selected = {true}), MUI is overriding it by default class from theme (theme.palette.action.selected). I’d like to know is it normal behaviour or is it a bug (I has fixed it in my local repo and can make pull request)? Thx
- [v] This is not a v0.x issue.
- [v] I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
I’d like that background color of ListItem was ‘red’.
Current Behavior 😯
The background color of ListItem is ‘rgba(0, 0, 0, 0.14)’.
Steps to Reproduce 🕹
import List from '@material-ui/core/List'
import ListItem from '@material-ui/core/ListItem'
import { withStyles } from '@material-ui/core/styles'
const styles = theme => ({
root: {
},
selected: {
backgroundColor: 'red',
},
})
function Demo(props) {
const { classes } = props
return (
<List component="nav">
<ListItem selected={true}
classes={{
selected: classes.selected
}}>
TEST
</ListItem>
</List>
)
}
export default withStyles(styles)(Demo)
Context 🔦
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.5.1 |
React | 16.6.3 |
Browser | Chrome, Safari |
TypeScript | No |
etc. |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:22
- Comments:12 (8 by maintainers)
Top Results From Across the Web
[ListItem] Custom background color always has overridden by ...
When I'm trying override background color of root node for ListItem( the attribute selected = {true}), MUI is overriding it by default class ......
Read more >How to change background color of a selected ItemList ...
const muiTheme = createMuiTheme({ overrides: { MuiListItem: { root: ... Change default selected gray color by passing selected style like this. <ListItem ......
Read more >How to customize - Material UI - MUI
Learn how to customize Material UI components by taking advantage of different strategies for specific use cases.
Read more >Overrides - Material-UI
The first way to override the style of a component is to use class names. Every component provides a className property which is...
Read more >Style library interoperability - Material UI - MUI
Note: If you are using Emotion and have a custom cache in your app, that one will override the one coming from MUI....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Rombs The correct solution is the following:
https://codesandbox.io/s/pk5w045pp7?file=/src/demo.js
You can learn more in https://material-ui.com/customization/components/#pseudo-classes.
With v4.0.0-beta.1 you can do:
https://codesandbox.io/s/xwor26oqo
cc @iossocket @ShogunRoss @iwknow @chpinan1128 @ndibek @jay-almaraz @HorizonShadow @TidyIQ I would love to learn more what would be a great solution for you guys.