Skip to content

Commit 8b7448e

Browse files
committed
fix: close MobileNav on click list item
1 parent c8f9d31 commit 8b7448e

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

components/main-nav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ export function MainNav({ items }: MainNavProps) {
5454
</nav>
5555
) : null}
5656
<button
57-
className="flex items-center space-x-2 md:hidden"
57+
className="flex items-center space-x-2 md:hidden focus-visible:outline-0 focus-visible:border-0 focus-within:outline-0 focus-within:border-0"
5858
onClick={() => setShowMobileMenu(!showMobileMenu)}
5959
>
6060
{showMobileMenu ? <Icons.cancel /> : <Icons.logo className="w-6 h-6 dark:invert"/>}
6161
<span className="font-bold">Menu</span>
6262
</button>
6363
{showMobileMenu && items && (
64-
<MobileNav items={items} />
64+
<MobileNav items={items} setShowMobileMenu={setShowMobileMenu} />
6565
)}
6666
</div>
6767
<nav>

components/mobile-nav.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import * as React from "react";
22
import Link from "next/link";
33

4+
import { cn } from "@/lib/utils";
45
import { MainNavItem } from "@/types";
6+
import { Icons } from "@/components/icons";
57
import { siteConfig } from "@/config/site";
6-
import { cn } from "@/lib/utils";
78
import { useLockBody } from "@/hooks/use-lock-body";
8-
import { Icons } from "@/components/icons";
99

1010
interface MobileNavProps {
11-
items: MainNavItem[]
11+
items: MainNavItem[],
12+
setShowMobileMenu: React.Dispatch<React.SetStateAction<boolean>>,
1213
children?: React.ReactNode
1314
}
1415

15-
export function MobileNav({ items }: MobileNavProps) {
16+
export function MobileNav({ items, setShowMobileMenu }: MobileNavProps) {
1617
useLockBody();
1718

1819
return (
@@ -31,6 +32,7 @@ export function MobileNav({ items }: MobileNavProps) {
3132
"flex w-full items-center rounded-md py-2 font-medium hover:underline",
3233
item.disabled && "cursor-not-allowed opacity-60"
3334
)}
35+
onClick={() => !item.disabled && setShowMobileMenu(false) }
3436
>
3537
{item.title}
3638
</Link>

config/nav.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ export const navConfig: NavConfig = {
88
},
99
{
1010
title: "Blog",
11-
href: "/blog"
11+
href: "/blog",
12+
disabled: true // Pending Feature Built
13+
},
14+
{
15+
title: "Tools",
16+
href: "/#tools"
1217
},
1318
{
1419
title: "Projects",
1520
href: "/#projects"
1621
},
17-
{
18-
title: "Tools",
19-
href: "/#tools"
20-
}
2122
]
2223
}

styles/globals.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
}
7676
}
7777

78+
html {
79+
@apply scroll-smooth;
80+
}
81+
7882
.m-itbey {
7983
@apply inline-flex gap-1 items-center align-bottom
8084
}

0 commit comments

Comments
 (0)