Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IconMenu] Change IconMenu to conditionally merge button styles #5496

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/IconMenu/IconMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import propTypes from '../utils/propTypes';
import Menu from '../Menu/Menu';
import Popover from '../Popover/Popover';
import warning from 'warning';
import deprecated from '../utils/deprecatedPropType';

class IconMenu extends Component {
static muiName = 'IconMenu';
Expand Down Expand Up @@ -42,7 +43,7 @@ class IconMenu extends Component {
/**
* Override the inline-styles of the underlying icon element.
*/
iconStyle: PropTypes.object,
iconStyle: deprecated(PropTypes.object, 'Add the "iconStyle" prop to the "iconButtonElement" instead.'),
/**
* Override the inline-styles of the menu element.
*/
Expand Down Expand Up @@ -268,10 +269,11 @@ class IconMenu extends Component {
warning(iconButtonElement.type.muiName !== 'SvgIcon',
`Material-UI: You shoud not provide an <SvgIcon /> to the 'iconButtonElement' property of <IconMenu />.
You should wrapped it with an <IconButton />.`);

const iconButton = React.cloneElement(iconButtonElement, {
onKeyboardFocus: onKeyboardFocus,
iconStyle: Object.assign({}, iconStyle, iconButtonElement.props.iconStyle),
iconStyle: iconStyle ?
Object.assign({}, iconStyle, iconButtonElement.props.iconStyle) :
iconButtonElement.props.iconStyle,
onTouchTap: (event) => {
this.open(Events.isKeyboard(event) ? 'keyboard' : 'iconTap', event);
if (iconButtonElement.props.onTouchTap) {
Expand Down
23 changes: 23 additions & 0 deletions src/IconMenu/IconMenu.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-env mocha */
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import getMuiTheme from '../styles/getMuiTheme';

import IconMenu from './IconMenu';

describe('<IconMenu />', function() {
const muiTheme = getMuiTheme();
const shallowWithContext = (node) => shallow(node, {context: {muiTheme}});
it('should not leak an iconStyle property', () => {
const wrapper = shallowWithContext(
<IconMenu
iconButtonElement={<div className="my-icon-button" />}
>
<div className="some-div" />
</IconMenu>
);
const buttonProps = wrapper.find('.my-icon-button').props();
assert.strictEqual(buttonProps.iconStyle, undefined);
});
});