Material-ui: style property does not affect component

Created on 17 Jun 2017  路  6Comments  路  Source: mui-org/material-ui

I set style on NavigationMenu component, but in the browser it does not affect component's style.

const MyMenu = (props) => (
    <IconMenu
        {...props}
        iconButtonElement={
            <IconButton>
                <NavigationMenu style={{color: '#ffffff', fill: '#ffffff'}} />
            </IconButton>
        }
        targetOrigin={{horizontal: 'right', vertical: 'top'}}
        anchorOrigin={{horizontal: 'right', vertical: 'top'}}
    >
        <MenuItem primaryText="Calculator" />
    </IconMenu>
);

I inspect with React plugin and I see this:
image

Most helpful comment

I have the same problem with Drawer but not with other things like Button

All 6 comments

import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';

let NavigationMenu = (props) => (
  <SvgIcon {...props}>
    <path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/>
  </SvgIcon>
);
NavigationMenu = pure(NavigationMenu);
NavigationMenu.displayName = 'NavigationMenu';
NavigationMenu.muiName = 'SvgIcon';

export default NavigationMenu;

https://github.com/callemall/material-ui/blob/ccf712c5733508784cd709c18c29059542d6aad1/src/svg-icons/navigation/menu.js

Don't understand the point? Why it does not set my custom style? Is it pure that somehow blocks it?

I have the same problem with Drawer but not with other things like Button

Have the same issue with Drawer. Cannot manually style zIndex

I think I found the solution.

In my case it's the IconButton that messes up. <NavigationMenu style={{color: '#ffffff', fill: '#ffffff'}} /> is its children, and in IconButton's code they use the following (shortened):

class IconButton extends Component {

  static defaultProps = {
    ....
    iconStyle: {},
    ...
  };

  render () {

      const childrenStyle = iconStyle;

      return (
        ...
        {extendChildren(children, {
          style: childrenStyle,
        })}
        ...
      );
  }
}

extendChildren takes the children, clones them and merges the properties given in the second argument. That's how my children's style gets overriden by iconStyle set to {} by default.

The solution is to set the iconStyle of wrapping element (IconButtonin my case), instead of setting style of the target element directly (NavigationMenu in my case).

What do you guys have the Drawer wrapped in (give code excerpt)?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanflorence picture ryanflorence  路  3Comments

finaiized picture finaiized  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

rbozan picture rbozan  路  3Comments

TimoRuetten picture TimoRuetten  路  3Comments