How to change background color of drawer component materialui in react?

2.5k views Asked by At

I wanted to change the background color of the drawer component in react but I always am only able to change the entire background behind the drawer the field with the items or nothing but not the entire white area. Here is my code:

const useStyles = makeStyles({
    MuiDrawer: {
      backgroundColor: "#5d001e",
    },
    list: {
      width: 250,
    },
    linkText: {
      textDecoration: `none`,
      textTransform: `uppercase`,
      color: `black`,
    },
  })


return (
        <>
        <React.Fragment>
        <TheIconButton
          edge="start"
          aria-label="menu"
          onClick={toggleDrawer("right", true)}>
          <Menu />
        </TheIconButton>
        <Drawer anchor="right" open={state.right} onOpen={toggleDrawer("right", true)} onClose={toggleDrawer("right", false)} className={classes.MuiDrawer}>
        {sideDrawerList("right")}
        </Drawer>
      </React.Fragment>
        </>
    )

enter image description here

Any ideas on how to target it ? I also tried forcing it with a class in a css file but it did not work....

1

There are 1 answers

0
95faf8e76605e973 On BEST ANSWER

Target the Drawer paper

const useStyles = makeStyles({
  MuiDrawer: {
    backgroundColor: "#5d001e"
  }
});

<Drawer
  classes={{paper: classes.MuiDrawer}}
>