I have a disabled list item that contains a button that I want enabled.
The Mui-disabled
class on the parent disabled everything all the way down.
Is there a way to override this?
I have a disabled list item that contains a button that I want enabled.
The Mui-disabled
class on the parent disabled everything all the way down.
Is there a way to override this?
The ListItemButton
which is disabled has the pointer-events
set to none
so you can't click anything inside. To resolve that override your inner button again:
V5
import Button, { buttonClasses } from "@mui/material/Button";
<List
sx={{
[`&& .${buttonClasses.disabled}`]: {
opacity: 1,
// anything that's not a button inside ListItem
[`& > :not(.${buttonClasses.root})`]: {
opacity: (theme) => theme.palette.action.disabledOpacity
},
// inner button
[`& > .${buttonClasses.root}`]: {
pointerEvents: "auto"
}
}
}}
>
V4
const useStyles = makeStyles(theme => ({
list: {
'&& .Mui-disabled': {
opacity: 1,
'& > :not(.MuiButton-root)': {
opacity: theme.palette.action.disabledOpacity
},
'& > .MuiButton-root': {
pointerEvents: "auto"
},
},
}
}));
<List className={classes.list}
My problem was in opacity. When I apply the "disabled" prop to the ListItem, it will apply opacity: 0.38, to the li element. So I just put
sx={{ opacity: disabled ? 0.38 : 1 }}
to each element inside except the required one. It looks like a bypass, but it works.