A warning when creating an IconMenu and putting a FlatButton as the iconButtonElement property
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'}
/>
}
/>
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'}}
/>
}
/>
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