From 2512467bd1a3743fdcfc81a3a4028b7b3f96019a Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 6 Sep 2022 21:51:35 +0300 Subject: [PATCH] hide mobile menu on navigate --- src/components/Menu/index.tsx | 29 ++++++++++++++++++----------- src/components/Navigation/index.tsx | 3 +++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/Menu/index.tsx b/src/components/Menu/index.tsx index 83cbea2e..f3a2827a 100644 --- a/src/components/Menu/index.tsx +++ b/src/components/Menu/index.tsx @@ -11,9 +11,10 @@ let cx = classnames.bind(s) export type MenuProps = { vertical?: boolean items: IMenu[] + onItemClick?: (item: IMenu) => void } -export const Menu: React.FC = ({ vertical = false, items }) => { +export const Menu: React.FC = ({ vertical = false, onItemClick, items }) => { const router = useRouter() return ( @@ -21,18 +22,24 @@ export const Menu: React.FC = ({ vertical = false, items }) => { { items.map(item => { const current = router.asPath === item.href - const href = current ? undefined : item.href + const href = current + ? undefined + : item.href + const className = !href + ? `${s.menuItem} ${s.current}` + : `${s.menuItem} ${s.active}` - if (!href) { - return ( - - {item.name} - - ) - } return ( - - {item.name} + { + if (typeof onItemClick === "function") { + onItemClick(item) + } + }} + > + {item.name} ) }) diff --git a/src/components/Navigation/index.tsx b/src/components/Navigation/index.tsx index 73f3893c..d5be333c 100644 --- a/src/components/Navigation/index.tsx +++ b/src/components/Navigation/index.tsx @@ -49,6 +49,9 @@ export const Navigation: React.FC = props => { {collapseMenu ? null : ( { + toggleOpen(false) + }} /> )}