Skip to content

Commit baf94f6

Browse files
authored
Avoid multiple context submenus from being visible at once (#5155)
1 parent a56c995 commit baf94f6

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/core/ui/CascadingMenu.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function CascadingMenuItem({
5353
onClick?.(event)
5454
}}
5555
onMouseOver={() => {
56+
// Close any existing child submenu when hovering over a regular menu item
57+
// Note: This logic is duplicated in CascadingSubmenu for consistency
5658
if (parentPopupState?.childHandle) {
5759
parentPopupState.childHandle.close()
5860
parentPopupState.setChildHandle(undefined)
@@ -80,9 +82,25 @@ function CascadingSubmenu({
8082
parentPopupState,
8183
})
8284

85+
const { onMouseOver: originalOnMouseOver, ...hoverProps } =
86+
bindHover(popupState)
87+
8388
return (
8489
<>
85-
<MenuItem {...bindFocus(popupState)} {...bindHover(popupState)}>
90+
<MenuItem
91+
{...bindFocus(popupState)}
92+
{...hoverProps}
93+
onMouseOver={event => {
94+
// Close any existing sibling submenus before opening this one
95+
// Note: This logic is duplicated from CascadingMenuItem for consistency
96+
if (parentPopupState?.childHandle) {
97+
parentPopupState.childHandle.close()
98+
parentPopupState.setChildHandle(undefined)
99+
}
100+
// Call the original hover handler to open this submenu
101+
originalOnMouseOver(event)
102+
}}
103+
>
86104
{Icon ? (
87105
<ListItemIcon>
88106
<Icon />

0 commit comments

Comments
 (0)