Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3590: TieredMenu hide on leaf click #3591

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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