Skip to content

Commit

Permalink
Close context menu on item click in Chip component (#271)
Browse files Browse the repository at this point in the history
Backport of #263
  • Loading branch information
neeilya authored Apr 24, 2019
1 parent 59f2ca5 commit 187db2f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/app/src/components/Layout/Menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import React, { cloneElement, isValidElement } from 'react';
import isFunction from 'lodash-es/isFunction';
import Menu from '@material-ui/core/Menu';
import IconButton from '@material-ui/core/IconButton';
import MoreHorizontalIcon from '../../assets/MoreHorizontalIcon';
Expand Down Expand Up @@ -38,7 +39,18 @@ class ChipMenu extends React.Component {
open={Boolean(this.state.anchorEl)}
onClose={this.handleClose}
>
{this.props.menuItems}
{this.props.menuItems.map(menuItem => {
const onClick = e => {
if (isFunction(menuItem.props.onClick)) {
menuItem.props.onClick(e);
}
this.handleClose(e);
};

return isValidElement(menuItem)
? cloneElement(menuItem, { onClick })
: menuItem;
})}
</Menu>
</React.Fragment>
);
Expand Down

0 comments on commit 187db2f

Please sign in to comment.