Material-ui: Active menu item

Created on 11 Aug 2016  路  9Comments  路  Source: mui-org/material-ui

Description

I am using MenuItem within a Drawer and would like to have the option to define an active item (e.g. if the user is at /home then the Home MenuItem should be highlighted.

Menu enhancement

Most helpful comment

Wondering how they do this on the material-ui demo page?

All 9 comments

These two issues will be easier to discuss if you split them up.

Wondering how they do this on the material-ui demo page?

I would love it if they would publish an uncompiled demo of the material-ui website too.
The submenus, the active features are not part of the docs

You can see the doc source here :
https://github.com/callemall/material-ui/blob/master/docs/src/app/components/AppNavDrawer.js

There are actually not using MenuItem but ListItem instead, and leveraging the makeSelectable function of this module to create a SelectableList.

Not very straightfroward.. would be very nice if menu item make "selectable" component more accesible.

Here's what I did

` 
//inside render

     if(Store.app == true) // Mobx Store. you can use component state as well
{
var backgroundhover = {
  backgroundColor: '#E8E8E8',
}}
else if ((Store.app == false)) {
 var backgroundhover = {
  backgroundColor: '#FFFFFF',
} }
          // Inside Return
 <MenuItem style={backgroundhover} onClick={this.showApp} primaryText="App" > </MenuItem>
`

I render the menu items like this, using react-router v3:

this.props.childRoutes.map(route => (
   <MenuItem
     key={route.path}
     style={
       this.props.router.isActive(route.path) ? {
         ...styles.item,
         ...styles.active,
       } : styles.item
     }
     onTouchTap={e => this.handleNavigate(e, route.path)}
   >
      { route.title }
  </MenuItem>
));

Use shouldComponentUpdate to improve performance or no need to array.prototype.map if your menu items don't change.

You can use the selected property on the v1-beta branch.

Could someone add this to the docs. I can't find anything about makeSelectable or selected

@lunchboxer You can find it here: https://material-ui-next.com/api/menu-item/#menuitem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mb-copart picture mb-copart  路  3Comments

pola88 picture pola88  路  3Comments

zabojad picture zabojad  路  3Comments

finaiized picture finaiized  路  3Comments

revskill10 picture revskill10  路  3Comments