Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI: drawer with expandable side menu

Using Material UI, how can I construct a Drawer with expandable menu items like the one on the material-ui.com site?

So I want something like this: enter image description here

Each menu item (in bold) can expand to reveal sub-menu items.

How can this be achieved with Material UI?

like image 368
etayluz Avatar asked Jun 28 '18 14:06

etayluz


1 Answers

you need a function open and close collapse

 const [openCollapse, setOpenCollapse] = React.useState(false);    

 function handleOpenSettings(){
    setOpenCollapse(!openCollapse);
 }

return(
        <Drawer>
            <ListItem button onClick={handleOpenSettings}>
              <ListItemIcon>
                <Settings />
              </ListItemIcon>
              <ListItemText primary="Settings" />
              {openCollapse ? <ExpandLess /> : <ExpandMore />}
            </ListItem>
            <Collapse in={openCollapse} timeout="auto" unmountOnExit>
            <List component="div" disablePadding>
              <ListItem button className={classes.nested}>
                <ListItemIcon>
                  <Settings />
                </ListItemIcon>
                <ListItemText inset primary="Starred" />
              </ListItem>
            </List>
          </Collapse>
        </<Drawer>
)

DEMO https://material-ui.com/components/lists/#simple-list

like image 187
Adriano Chiliseo Avatar answered Oct 25 '22 11:10

Adriano Chiliseo