From 0a1e5568c979096e614ef45b6aff524046af50b8 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Tue, 7 Nov 2023 15:59:31 +0100 Subject: [PATCH] feat(menu): add isActive prop to override state --- client/src/ui/molecules/menu/index.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client/src/ui/molecules/menu/index.tsx b/client/src/ui/molecules/menu/index.tsx index f97004f76665..f89f90ec1440 100644 --- a/client/src/ui/molecules/menu/index.tsx +++ b/client/src/ui/molecules/menu/index.tsx @@ -6,18 +6,27 @@ import "./index.scss"; interface MenuProps { menu: MenuEntry; + isActive?: boolean; isOpen: boolean; toggle: (id: string) => void; } -export const Menu = ({ menu, isOpen, toggle }: MenuProps) => { +export const Menu = ({ + menu, + isActive = undefined, + isOpen, + toggle, +}: MenuProps) => { const { pathname } = useLocation(); const gleanClick = useGleanClick(); const buttonId = `${menu.id}-button`; const submenuId = `${menu.id}-menu`; - const isActive = menu.to && pathname.startsWith(menu.to.split("#", 2)[0]); + isActive = + isActive ?? + (typeof menu.to === "string" && + pathname.startsWith(menu.to.split("#", 2)[0])); const hasAnyDot = menu.items.some((item) => item.dot); return (