Reputation: 369
In my component I need to override css parameter "overflow-y". This parameter is described in class .MuiDrawer-paper. Usually to override css is piece of cake via makeStyles. But in this component has two divs. Parent container and daughter div. And when I set overrided class like:
const useStyles = makeStyles((theme) => ({
paper: {
overflowY: 'unset',
},
)};
...
className={classes.paper}
Parent div gets this class and it does not have any sense. Because I need to override daughter class. I tried to do some thing like this:
className={{ paper: classes.paper }}
But in this case class wan't picked... What should I do?
Upvotes: 1
Views: 4960
Reputation: 1403
The top-voted answer in this thread contains legacy code (makeStyles
). I was able to override CSS on a child element of a MUI component via the styled
API (migration guide):
const StyledMUIComponent = styled(MUIComponentName)({
"& .child-class-to-target": {
overflowY: 'unset'
}
})
Upvotes: 0
Reputation: 13682
The correct way to override material ui classes is to make use of classes
prop on Drawer
component instead of className
.
Read more about overriding classes
const useStyles = makeStyles((theme) => ({
paper: {
overflowY: 'unset',
},
)};
...
<Drawer
classes={{
paper: classes.paper,
}}
anchor="left"
open={open}
/>
Upvotes: 6
Reputation: 10254
I have 2 options.
!important
const useStyles = makeStyles((theme) => ({
paper: {
overflowY: 'unset !important',
},
)};
styles
property.<Drawer style={{overflowY: 'unset'}} />
I prefer to use styles
property.
Upvotes: -1