Skip to content

Commit

Permalink
feat(menu): add isActive prop to override state
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Nov 8, 2023
1 parent 7ce3528 commit 0a1e556
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/src/ui/molecules/menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 0a1e556

Please sign in to comment.