mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 20:53:24 +10:00
MenuLabel can react to isOpen state
This commit is contained in:
parent
88cf0a4acc
commit
8db40584f2
3 changed files with 13 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -16,3 +16,6 @@
|
|||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Default isOpen class - no styles yet */
|
||||
.isOpen {}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue