Skip to content

Commit

Permalink
remove flyoutMenu from listGroupItem props before render
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsongl committed Mar 11, 2019
1 parent 0dc16d2 commit 8a9d393
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
10 changes: 0 additions & 10 deletions src/components/list_group/list_group_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const EuiListGroupItem = ({
onClick,
size,
showToolTip,
flyoutMenu, // eslint-disable-line no-unused-vars
...rest
}) => {
const classes = classNames(
Expand Down Expand Up @@ -174,15 +173,6 @@ EuiListGroupItem.propTypes = {
alwaysShow: PropTypes.bool,
}),

/**
* See `EuiNavDrawer`. `flyoutMenu` provides a `title` and `listItems` to the
* `EuiNavDrawerFlyout` component while also overriding the `EuiListGroupItem` `onClick` prop
*/
flyoutMenu: PropTypes.shape({
title: PropTypes.string,
listItems: PropTypes.array,
}),

onClick: PropTypes.func,
};

Expand Down
28 changes: 24 additions & 4 deletions src/components/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,20 @@ export class EuiNavDrawer extends Component {
// 3a. Loop through list items passed as an array on EuiListGroup
if (typeof child.props.listItems !== 'undefined') {
const listItemArray = child.props.listItems;
listItemArray.map((item) => {
const modifiedListItems = listItemArray.map((item) => {
// 4. If there is a flyoutMenu prop, then add an onClick prop
if (item.flyoutMenu) {
item.onClick = () => this.expandFlyout(item.flyoutMenu.listItems, item.flyoutMenu.title);
const { flyoutMenu, ...itemProps } = item;
return {
onClick: () => this.expandFlyout(flyoutMenu.listItems, flyoutMenu.title),
...itemProps
};
}
return item;
});
child = ({ ...child, ...{
props: ({ ...child.props, ...{ listItems: modifiedListItems } })
} });
}

// 3b. Loop through list itmes passed as separate EuiListGroupItem components
Expand All @@ -212,9 +220,15 @@ export class EuiNavDrawer extends Component {
: null,
});

// Remove `flyoutMenu` so it doesn't get passed to the DOM
const {
flyoutMenu, // eslint-disable-line no-unused-vars
...itemProps
} = item.props;

child = React.cloneElement(child, {
key: childIndex,
children: item
children: ({ ...item, ...{ props: { ...itemProps } } })
});
// If more than one child, then there is an index
} else {
Expand All @@ -231,7 +245,13 @@ export class EuiNavDrawer extends Component {
: null,
});

return item;
// Remove `flyoutMenu` so it doesn't get passed to the DOM
const {
flyoutMenu, // eslint-disable-line no-unused-vars
...itemProps
} = item.props;

return ({ ...item, ...{ props: { ...itemProps } } });
})
});
}
Expand Down

0 comments on commit 8a9d393

Please sign in to comment.