材质UI:带可扩展侧菜单的抽屉

时间:2018-06-28 14:26:05

标签: reactjs menu material-ui side-menu

使用Material UI,如何构建带有可扩展菜单项的抽屉,例如material-ui.com网站上的菜单项?

所以我想要这样的东西: enter image description here

每个菜单项(以粗体显示)可以展开以显示子菜单项。

如何通过Material UI做到这一点?

1 个答案:

答案 0 :(得分:0)

您需要打开和关闭折叠功能

 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>
)

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