Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open nested menu in main menu - material-ui (react)

In Material UI I can program nested menus and dropdown menus. But I haven`t found an example to open the nested menus in the main menu.

With nested menus and dropdown menus the nested menus open as a new window beside or above the main menu:

Menu with nested menu opened to the right

But I want the nested menus opened in the main menu:

Nested menus open in main menu

How do I achieve this?

like image 269
Paul Avatar asked Jul 17 '26 17:07

Paul


1 Answers

You're using the wrong component. Use a List with ListItems that have NestedItems

  <List>
    <Subheader>Nested List Items</Subheader>
    <ListItem primaryText="Sent mail" leftIcon={<ContentSend />} />
    <ListItem primaryText="Drafts" leftIcon={<ContentDrafts />} />
    <ListItem
      primaryText="Inbox"
      leftIcon={<ContentInbox />}
      initiallyOpen={true}
      primaryTogglesNestedList={true}
      nestedItems={[
        <ListItem
          key={1}
          primaryText="Starred"
          leftIcon={<ActionGrade />}
        />,
        <ListItem
          key={2}
          primaryText="Sent Mail"
          leftIcon={<ContentSend />}
          disabled={true}
          nestedItems={[
            <ListItem key={1} primaryText="Drafts" leftIcon={<ContentDrafts />} />,
          ]}
        />,
        <ListItem
          key={3}
          primaryText="Inbox"
          leftIcon={<ContentInbox />}
          open={this.state.open}
          onNestedListToggle={this.handleNestedListToggle}
          nestedItems={[
            <ListItem key={1} primaryText="Drafts" leftIcon={<ContentDrafts />} />,
          ]}
        />,
      ]}
    />
  </List>
like image 55
Dale Francis Avatar answered Jul 19 '26 05:07

Dale Francis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!