From 5badb392599a1434dcadd4f09200fa735b4c7934 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 8 Jan 2026 11:44:00 +0000 Subject: [PATCH] Avoid closing nested menu on click (#30479) GitOrigin-RevId: 0f966b53ee5bfd8b4bacdf7b259f3e8cab2858c8 --- .../components/menu-bar/menu-bar-dropdown.tsx | 29 ++++++++++--------- .../context/nestable-dropdown-context.tsx | 17 ++++++++++- .../stylesheets/components/dropdown-menu.scss | 10 +++++-- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/services/web/frontend/js/shared/components/menu-bar/menu-bar-dropdown.tsx b/services/web/frontend/js/shared/components/menu-bar/menu-bar-dropdown.tsx index 5464d6cd83..834a1dbc32 100644 --- a/services/web/frontend/js/shared/components/menu-bar/menu-bar-dropdown.tsx +++ b/services/web/frontend/js/shared/components/menu-bar/menu-bar-dropdown.tsx @@ -39,13 +39,9 @@ export const MenuBarDropdown: FC< }) }, [id, setSelected]) + const active = selected === id return ( - + {title} - - {children} - + {active && ( + + {children} + + )} ) } @@ -109,7 +107,10 @@ export const NestedMenuBarDropdown: FC< }, [id, setSelected]) const onToggle = useCallback( (show: boolean) => { - setSelected(show ? id : null) + // Only handle opening + if (show) { + setSelected(id) + } }, [setSelected, id] ) @@ -130,9 +131,11 @@ export const NestedMenuBarDropdown: FC< > {title} - - {children} - + {active && ( + + {children} + + )} ) } diff --git a/services/web/frontend/js/shared/context/nestable-dropdown-context.tsx b/services/web/frontend/js/shared/context/nestable-dropdown-context.tsx index 7f949f4ebe..b1c9d15df8 100644 --- a/services/web/frontend/js/shared/context/nestable-dropdown-context.tsx +++ b/services/web/frontend/js/shared/context/nestable-dropdown-context.tsx @@ -1,4 +1,11 @@ -import { createContext, Dispatch, FC, SetStateAction, useState } from 'react' +import { + createContext, + Dispatch, + FC, + SetStateAction, + useEffect, + useState, +} from 'react' export type NestableDropdownContextType = { selected: string | null @@ -14,6 +21,14 @@ export const NestableDropdownContextProvider: FC< React.PropsWithChildren<{ id: string }> > = ({ id, children }) => { const [selected, setSelected] = useState(null) + + useEffect(() => { + return () => { + // unset selection on unmount + setSelected(null) + } + }, []) + return (