Skip to content

Commit 76b99d5

Browse files
committed
feat: avoid rendering desktop nav menu content on mobile
1 parent e06d8f7 commit 76b99d5

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

src/components/Nav/Menu/index.tsx

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as NavigationMenu from "@radix-ui/react-navigation-menu"
44

55
import { Button } from "@/components/Buttons"
66

7+
import { isMobile } from "@/lib/utils/isMobile"
8+
79
import { MAIN_NAV_ID, NAV_PY, SECTION_LABELS } from "@/lib/constants"
810

911
import type { NavSections } from "../types"
@@ -26,6 +28,8 @@ const Menu = ({ sections, ...props }: NavMenuProps) => {
2628
onClose,
2729
} = useNavMenu(sections)
2830

31+
const isDesktop = !isMobile()
32+
2933
return (
3034
<Box {...props}>
3135
<NavigationMenu.Root
@@ -78,32 +82,37 @@ const Menu = ({ sections, ...props }: NavMenuProps) => {
7882
</Text>
7983
</Button>
8084
</NavigationMenu.Trigger>
81-
<NavigationMenu.Content asChild>
82-
{/**
83-
* This is the CONTAINER for all three menu levels
84-
* This renders inside the NavigationMenu.Viewport component
85-
*/}
86-
<Box
87-
as={motion.div}
88-
variants={containerVariants}
89-
initial={false}
90-
animate={isOpen ? "open" : "closed"}
91-
position="absolute"
92-
top="19"
93-
insetInline="0"
94-
shadow="md"
95-
border="1px"
96-
borderColor={menuColors.stroke}
97-
bg={menuColors.lvl[1].background}
98-
>
99-
<SubMenu
100-
lvl={1}
101-
items={items}
102-
activeSection={activeSection}
103-
onClose={onClose}
104-
/>
105-
</Box>
106-
</NavigationMenu.Content>
85+
86+
{/* avoid rendering desktop menu on mobile */}
87+
{/* Desktop Menu content */}
88+
{isDesktop && (
89+
<NavigationMenu.Content asChild>
90+
{/**
91+
* This is the CONTAINER for all three menu levels
92+
* This renders inside the NavigationMenu.Viewport component
93+
*/}
94+
<Box
95+
as={motion.div}
96+
variants={containerVariants}
97+
initial={false}
98+
animate={isOpen ? "open" : "closed"}
99+
position="absolute"
100+
top="19"
101+
insetInline="0"
102+
shadow="md"
103+
border="1px"
104+
borderColor={menuColors.stroke}
105+
bg={menuColors.lvl[1].background}
106+
>
107+
<SubMenu
108+
lvl={1}
109+
items={items}
110+
activeSection={activeSection}
111+
onClose={onClose}
112+
/>
113+
</Box>
114+
</NavigationMenu.Content>
115+
)}
107116
</NavigationMenu.Item>
108117
)
109118
})}

0 commit comments

Comments
 (0)