MenuLabel can react to isOpen state

This commit is contained in:
Vesa Luusua 2017-07-21 14:56:23 +03:00
parent 88cf0a4acc
commit 8db40584f2
3 changed files with 13 additions and 3 deletions

View file

@ -98,7 +98,10 @@ class Menu extends Component {
if (child.type === MenuLabel) {
// MenuLabel needs toggleOpen function
// We pass that directly so that component user doesn't need to worry about that
return React.cloneElement(child, { onToggleActive: this.toggleOpen });
return React.cloneElement(child, {
isOpen: this.state.isOpen,
onToggleActive: this.toggleOpen,
});
} else if (child.type === MenuContent) {
// MenuContent needs some styling data (width, arrowPosition, and isOpen info)
// We pass those directly so that component user doesn't need to worry about those.

View file

@ -16,3 +16,6 @@
outline: none;
}
}
/* Default isOpen class - no styles yet */
.isOpen {}

View file

@ -35,11 +35,13 @@ class MenuLabel extends Component {
}
render() {
const { children, className, rootClassName } = this.props;
const { children, className, rootClassName, isOpen, isOpenClassName } = this.props;
const rootClass = rootClassName || css.root;
const isOpenClass = isOpenClassName || css.isOpen;
const classes = classNames(rootClass, className, {
[css.clickedWithMouse]: this.state.clickedWithMouse,
[isOpenClass]: isOpen,
});
return (
@ -58,11 +60,13 @@ MenuLabel.defaultProps = {
rootClassName: '',
};
const { func, node, string } = PropTypes;
const { bool, func, node, string } = PropTypes;
MenuLabel.propTypes = {
children: node.isRequired,
className: string,
isOpenClassName: string,
isOpen: bool,
onToggleActive: func,
rootClassName: string,
};