-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ListItem] Custom background color always has overridden by MUI style #13672
Labels
component: list
This is the name of the generic UI component, not the React module!
support: question
Community support but can be turned into an improvement
Comments
oliviertassinari
added
the
support: question
Community support but can be turned into an improvement
label
Nov 22, 2018
@Rombs The correct solution is the following: import React from "react";
import { List, ListItem, withStyles } from "@material-ui/core";
const StyledListItem = withStyles({
root: {
backgroundColor: "blue",
"&.Mui-selected": {
backgroundColor: "red"
}
},
})(ListItem);
function Demo() {
return (
<List component="nav">
<StyledListItem>default</StyledListItem>
<StyledListItem selected>selected pseudo-class</StyledListItem>
</List>
);
}
export default Demo; https://codesandbox.io/s/pk5w045pp7?file=/src/demo.js You can learn more in https://material-ui.com/customization/components/#pseudo-classes. |
2 tasks
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
oliviertassinari
added
the
component: list
This is the name of the generic UI component, not the React module!
label
Aug 15, 2020
That worked for me to also change background color when on no-hover device: import { withStyles, ListItem as MuiListItem } from '@material-ui/core'
export const ListItem = withStyles({
root: {
backgroundColor: '#fafafa',
'&:not(:last-child)': {
borderBottom: '1px solid rgba(0, 0, 0, 0.12)',
},
'@media (hover: none)': {
'&:hover': {
backgroundColor: '#fafafa',
},
},
},
})(MuiListItem) |
*withStyles-> now resides in : import { withStyles } from '@mui/styles'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
component: list
This is the name of the generic UI component, not the React module!
support: question
Community support but can be turned into an improvement
When 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
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 🕹
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: