Material-ui: how to add menu items to AppBar left default menu

Created on 23 Nov 2015  路  12Comments  路  Source: mui-org/material-ui

How to add menu items to the default left menu icon? I use the code below to add it, it seems over lay with the default 'menu' icon. I can tell because the menu icon becomes black instead of white by default.

  `<AppBar
    title="Foo"        
    iconElementLeft = {
      <IconMenu iconButtonElement={
        <IconButton iconClassName="material-icons" > menu </IconButton>
      }>
      <MenuItem primaryText="Refresh" />
      <MenuItem primaryText="Help" />
      <MenuItem primaryText="Sign out" />
    </IconMenu>
    }
  />`

I just want to add menu items to the left 'menu' icon menu, as if in the example
<AppBar title="Title" />
but in the example, they didn't add any menu items to the only left side menu icon button.

Also, does it work with react-router? Below code is NOT valid. How do I add link to the menu item, have to use event?

`<AppBar
    title="Foo"        
    iconElementLeft = {
      <IconMenu iconButtonElement={
        <IconButton iconClassName="material-icons" > menu </IconButton>
      } openDirection="bottom-right">

      <Link to="/bar"><MenuItem primaryText="Bar" /></Link>


    </IconMenu>
    }
  />`

How do I distinguish which item is clicked? value id and primaryText all cannot be gotten from the event.

`handleMenuClick: function(event) {
console.log(event.target);

},`
...

`<AppBar
    title="Well Factory Sim"        
    iconElementLeft = {
      <IconMenu iconButtonElement={
        <IconButton iconClassName="material-icons" > menu </IconButton>
      } openDirection="bottom-right"
      onItemTouchTap={this.handleMenuClick}>

      <MenuItem primaryText="a" value="a" id="a" />       
      <MenuItem primaryText="b" value="b" id="b" />       

    </IconMenu>
    }
  />`

Most helpful comment

I think the documentation can certainly be improved here. In the Simple Example (http://www.material-ui.com/#/components/app-bar) it says "By default, the left icon is a navigation-menu," but it's not at all obvious how to use it as an actual navigation-menu -- or even what a navigation-menu is, other than an icon.

All 12 comments

This is how I did it:

<AppBar
          title="Test"
          onLeftIconButtonTouchTap={this.handleToggle}
        />
        <LeftNav
            open={this.state.menuOpen}
            onRequestChange={open => this.setState({menuOpen: open})}
            docked={false}>

          <MenuItem onTouchTap={this.closeLeftNav} value={'/'} primaryText="Home"/>
     </LeftNav>

@treeder Thanks for your anwser.
@jma7889 That doesn't looks like an issue with material-ui, please use stackoverflow for questions. Unless you think we can improve the documentation, I will close the issue.

I think the documentation can certainly be improved here. In the Simple Example (http://www.material-ui.com/#/components/app-bar) it says "By default, the left icon is a navigation-menu," but it's not at all obvious how to use it as an actual navigation-menu -- or even what a navigation-menu is, other than an icon.

@oliviertassinari Would it be possible to address @Sigfried 's comment? I believe he makes a valid point. Furthermore, would be nice to see your team work through problems such as this!! Cheers!

@nejohnston Please check out the v1-beta version.

Thanks. Is there any guidance available on upgrading to v1-beta? Or any off-the-cuff opinions about how much one's application is likely to break in attempting to upgrade? There's probably a better place to ask or find the answer but I didn't see it with a cursory search.

Is there any guidance available on upgrading to v1-beta?

@Sigfried The best we have is #7195.

Or any off-the-cuff opinions about how much one's application is likely to break in attempting to upgrade?

It's a complete rewrite.

Excellent. So I won't be tempted to just jump in with my fingers crossed ;)

One of the worst libraries I've worked with. If I had to do that much by myself then why I'm choosing a library?

@ejoo Yes, why?

@ejoo Do you expect the library's maintainers to upgrade your code? :sweat_smile:

@leMaik I think he means why use the app bar if it's more work?

It's great for just having a title on the left and icon on the right... but if you want anything custom like a menu, and of course most people would, you end up fighting the app-bar more than it helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rbozan picture rbozan  路  3Comments

ghost picture ghost  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments

newoga picture newoga  路  3Comments

finaiized picture finaiized  路  3Comments