I have created a selectable component using Material-UI
let SelectableInfiniteList = makeSelectable(Infinite);
and put ListItem inside, now I want to change the default grayish color of a selected item, but I don't know how, if I give it a className
<ListItem className="list-item" primaryText={i}/>
and use list-item:focus selector I can change the background color as long as it is focused (but if I click somewhere else in the app) the focus is lost and the gray color shows up on the (still) selected item,
is there a way to change the selected item background color?
To change the color of Select component's border and arrow icon with React Material UI, we can use the '&:before' and '&:after' selectors and apply the styles for them. We call makeStyles with a function that returns an object with the select property set to an object with the drop down styles.
I had to use Global Theme override: https://material-ui.com/customization/components/#global-theme-override
const muiTheme = createMuiTheme({
overrides: {
MuiListItem: {
root: {
"&$selected": {
backgroundColor: "red",
"&:hover": {
backgroundColor: "orange",
},
},
},
button: {
"&:hover": {
backgroundColor: "yellow",
},
},
},
},
});
Change default selected gray color by passing selected
style like this.
<ListItem
button
selected={true}
classes={{ selected: classes.active }}>
<ListItemText primary={item.name} />
</ListItem>
Style object should be like this.
active: {
backgroundColor: "red"
}
Using Material UI v4 and this worked for me:
<ListItem button classes={{ root: classes.listItemRoot }}>
...
</ListItem>
with:
const useStyles = makeStyles((theme) => ({
listItemRoot: {
"&.Mui-selected": {
backgroundColor: 'red',
}
},
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With