Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92bec85

Browse files
committed
fix nav close and links
1 parent dc6dd48 commit 92bec85

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

app/(main)/layout.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { cn } from "@/lib/utils";
1717
import { ThemeProvider } from "@/components/theme-provider";
1818
import Link from "next/link";
1919
import { Button } from "@/components/ui/button";
20-
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
20+
import { Sheet, SheetClose, SheetContent, SheetTrigger } from "@/components/ui/sheet";
2121
import NavHeader from "@/components/nav-header";
2222
import Footer from "@/components/footer";
2323
import { Toaster } from "@/components/ui/sonner";
@@ -134,9 +134,7 @@ export default async function RootLayout({
134134
</SheetTrigger>
135135
<SheetContent side="right">
136136
<nav className="py-6 grid gap-2">
137-
<SheetTrigger asChild>
138-
<NavHeader navLinks={settings?.navLinks} sideOnly />
139-
</SheetTrigger>
137+
<NavHeader navLinks={settings?.navLinks} sideOnly />
140138
</nav>
141139
</SheetContent>
142140
</Sheet>

components/nav-header.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Settings } from "@/sanity/types";
44

55
import { useActivePath } from "@/lib/hooks";
66
import NavLink from "@/components/nav-link";
7+
import { SheetClose } from "./ui/sheet";
78

89
interface Props {
910
navLinks: Exclude<Settings["navLinks"], undefined> | undefined;
@@ -18,21 +19,36 @@ export default function NavHeader({
1819
...restProps
1920
}: Props) {
2021
const checkActivePath = useActivePath();
21-
2222
return (
2323
<>
2424
{navLinks
2525
?.filter((l) => (sideOnly ? true : l?.sideOnly !== true))
26-
?.map((l) => (
27-
<NavLink
28-
{...restProps}
29-
key={l._key}
30-
className={`${className || ""} ${checkActivePath(l.path) ? "underline decoration-primary" : ""}`}
31-
href={l?.path || "/"}
32-
>
33-
{l.title}
34-
</NavLink>
35-
))}
26+
?.map((l) =>
27+
sideOnly ? (
28+
<SheetClose asChild key={l._key}>
29+
<NavLink
30+
{...restProps}
31+
className={`${className || ""} ${
32+
checkActivePath(l.path) ? "underline decoration-primary" : ""
33+
}`}
34+
href={l?.path || "/"}
35+
>
36+
{l.title}
37+
</NavLink>
38+
</SheetClose>
39+
) : (
40+
<NavLink
41+
{...restProps}
42+
key={l._key}
43+
className={`${className || ""} ${
44+
checkActivePath(l.path) ? "underline decoration-primary" : ""
45+
}`}
46+
href={l?.path || "/"}
47+
>
48+
{l.title}
49+
</NavLink>
50+
),
51+
)}
3652
</>
3753
);
3854
}

0 commit comments

Comments
 (0)