Material-ui: IconMenu with FlatButton unknown props warning

Created on 30 Jul 2016  路  5Comments  路  Source: mui-org/material-ui

Problem description

A warning when creating an IconMenu and putting a FlatButton as the iconButtonElement property

Steps to reproduce

I've tried to add the following icon menu (For a user account with its name near it)

<IconMenu
    iconButtonElement={
        <FlatButton
            icon={<AccountCircleIcon />} //Thats the svg icon
            label={'User Name'}
        />
    }
/>

Versions

  • Material-UI: 0.15.2

Most helpful comment

Sorry to bring this up again but this still seems to happen (for me)
Happens with the above steps to reproduce and the following example

import AccountCircleIcon from 'material-ui/svg-icons/action/account-circle';

<IconMenu
    iconButtonElement={
        <FlatButton
            icon={<AccountCircleIcon />} //Thats the svg icon
            label={'User Name'}
            style={{color: 'white'}}
        />
    }
/>

All 5 comments

Same for IconMenu + RaisedButton with Material-UI 0.15.3:

<IconMenu iconButtonElement={<RaisedButton label="Test"/>}/>

The warning trace is:

Warning: Unknown prop iconStyle on

I'm still seeing the warnings in version 0.15.3 for disabledBackgroundColor and disabledLabelColor properties of the RaisedButton component.

react-unknown-props for disabledBackgroundColor and disabledLabelColor properties of the RaisedButton component.

v15.3.0

The root cause of this issue appears to be the merging of the iconStyle prop with the same prop of the iconElement that is being passed as a prop.

https://github.com/callemall/material-ui/blob/master/src/IconMenu/IconMenu.js#L272

    const iconButton = React.cloneElement(iconButtonElement, {
      onKeyboardFocus: onKeyboardFocus,
      iconStyle: Object.assign({}, iconStyle, iconButtonElement.props.iconStyle), // <--
      onTouchTap: (event) => {
        this.open(Events.isKeyboard(event) ? 'keyboard' : 'iconTap', event);
        if (iconButtonElement.props.onTouchTap) {
          iconButtonElement.props.onTouchTap(event);
        }
      },
      ref: 'iconButton',
    });

The Object.assign() call is passing an object as the iconStyle prop to the iconButton element, which will then pass it all the way down to the <button />.

A proposed fix would be to only try to merge the styles if iconButtonElement has an iconStyle prop defined. Something like this:

if (iconButtonElement.props.iconStyle) {
  iconButton.props.iconStyle = Object.assign({}, iconStyle, iconButtonElement.props.iconStyle);
}

Sorry to bring this up again but this still seems to happen (for me)
Happens with the above steps to reproduce and the following example

import AccountCircleIcon from 'material-ui/svg-icons/action/account-circle';

<IconMenu
    iconButtonElement={
        <FlatButton
            icon={<AccountCircleIcon />} //Thats the svg icon
            label={'User Name'}
            style={{color: 'white'}}
        />
    }
/>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

anthony-dandrea picture anthony-dandrea  路  3Comments

FranBran picture FranBran  路  3Comments

sys13 picture sys13  路  3Comments

chris-hinds picture chris-hinds  路  3Comments

activatedgeek picture activatedgeek  路  3Comments