Skip to content

Commit

Permalink
Fix #3590: TieredMenu hide on leaf click (#3591)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 8, 2022
1 parent a6ab507 commit d70236d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions components/lib/tieredmenu/TieredMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export const TieredMenu = React.memo(
};

const hide = (event) => {
targetRef.current = event.currentTarget;
setVisibleState(false);
props.onHide && props.onHide(event);
if (props.popup) {
targetRef.current = event.currentTarget;
setVisibleState(false);
props.onHide && props.onHide(event);
}
};

const onEnter = () => {
Expand Down Expand Up @@ -106,7 +108,7 @@ export const TieredMenu = React.memo(
onExited={onExited}
>
<div ref={menuRef} id={props.id} className={className} style={props.style} {...otherProps} onClick={onPanelClick}>
<TieredMenuSub menuProps={props} model={props.model} root popup={props.popup} />
<TieredMenuSub menuProps={props} model={props.model} root popup={props.popup} onHide={hide} />
</div>
</CSSTransition>
);
Expand Down
7 changes: 4 additions & 3 deletions components/lib/tieredmenu/TieredMenuSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const TieredMenuSub = React.memo((props) => {
}

if (!item.items) {
onLeafClick();
onLeafClick(event);
}
};

Expand Down Expand Up @@ -136,9 +136,10 @@ export const TieredMenuSub = React.memo((props) => {
return prevItem ? (DomHandler.hasClass(prevItem, 'p-disabled') || !DomHandler.hasClass(prevItem, 'p-menuitem') ? findPrevItem(prevItem) : prevItem) : null;
};

const onLeafClick = () => {
const onLeafClick = (event) => {
setActiveItemState(null);
props.onLeafClick && props.onLeafClick();
props.onLeafClick && props.onLeafClick(event);
props.onHide && props.onHide(event);
};

useMountEffect(() => {
Expand Down

0 comments on commit d70236d

Please sign in to comment.