Skip to content

Commit

Permalink
feat(MenuItem): add listClassName prop
Browse files Browse the repository at this point in the history
  • Loading branch information
bfbiggs committed Jan 25, 2020
1 parent 71a79e0 commit a1dd631
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions react/src/lib/MenuItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { UIDConsumer } from 'react-uid';
import { ListItem } from '@momentum-ui/react';
import ListContext from '../ListContext';
import SelectableContext from '../SelectableContext';
import { prefix } from '../utils/index';

class MenuItem extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -58,6 +59,7 @@ class MenuItem extends React.Component {
className,
isHeader,
isOpen,
itemClassName,
...props
} = this.props;
const { selectContext } = this.state;
Expand All @@ -70,7 +72,7 @@ class MenuItem extends React.Component {
]);

return (
<UIDConsumer name={id => `md-menu-item-${id}`}>
<UIDConsumer name={id => `${prefix}-menu-item-${id}`}>
{id => (
<SelectableContext.Provider value={selectContext}>
<ListContext.Consumer>
Expand All @@ -79,36 +81,37 @@ class MenuItem extends React.Component {
|| listContext
&& listContext.active
&& ReactDOM.findDOMNode(this.anchorRef)
&& ReactDOM.findDOMNode(this.anchorRef).attributes['data-md-event-key']
&& ReactDOM.findDOMNode(this.anchorRef).attributes['data-md-event-key'].value
&& ReactDOM.findDOMNode(this.anchorRef).attributes[`data-${prefix}-event-key`]
&& ReactDOM.findDOMNode(this.anchorRef).attributes[`data-${prefix}-event-key`].value
&& listContext.active.includes(
ReactDOM.findDOMNode(this.anchorRef)
.attributes['data-md-event-key']
.attributes[`data-${prefix}-event-key`]
.value
);

return(
<div
className={
'md-menu-item' +
`${(className && ` ${className}`) || ''}`
`${prefix}-menu-item` +
`${className && ` ${className}` || ''}`
}
aria-expanded={cxtActive}
aria-haspopup={!!children}
>
<ListItem
active={cxtActive}
className={`${(isHeader && `md-menu-item__header`) || ''}`}
className={
`${isHeader && `md-menu-item__header` || ''}` +
`${itemClassName && ` ${itemClassName}` || ''}`
}
focusOnLoad
isReadOnly={isHeader}
id={id}
ref={ref => this.anchorRef = ref}
role="menuitem"
{...otherProps}
>
{
children
}
{children}
</ListItem>
</div>
);
Expand All @@ -130,6 +133,8 @@ MenuItem.propTypes = {
isHeader: PropTypes.bool,
/** @prop Determines if MenuItem is open | false */
isOpen: PropTypes.bool,
/** @prop Optional list css class name | '' */
itemClassName: PropTypes.string,
/** @prop Set to keep the MenuItem open | false */
keepMenuOpen: PropTypes.bool,
/** @prop Callback function invoked when user taps on MenutItem | null */
Expand All @@ -145,6 +150,7 @@ MenuItem.defaultProps = {
className: '',
isHeader: false,
isOpen: false,
itemClassName: '',
keepMenuOpen: false,
onClick: null,
parentKeyDown: null,
Expand Down

0 comments on commit a1dd631

Please sign in to comment.