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 (