Skip to content

Commit 061c626

Browse files
authored
chore: always close the nav on tab change (#2660)
1 parent 0608139 commit 061c626

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use client";
2+
3+
import { useDispatchSidebarAction } from "@/state/navigation";
4+
5+
import { FernLink } from "./FernLink";
6+
7+
export function FernLinkTab({
8+
children,
9+
...props
10+
}: React.ComponentProps<typeof FernLink>) {
11+
const dispatch = useDispatchSidebarAction();
12+
return (
13+
<FernLink
14+
{...props}
15+
onClick={() => {
16+
dispatch({ type: "collapse-all" });
17+
}}
18+
>
19+
{children}
20+
</FernLink>
21+
);
22+
}

packages/fern-docs/bundle/src/components/header/HeaderTabsList.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { TabChild, hasRedirect } from "@fern-api/fdr-sdk/navigation";
77
import { cn } from "@fern-docs/components";
88
import { slugToHref } from "@fern-docs/utils";
99

10-
import { FernLink } from "@/components/FernLink";
1110
import { FaIconServer } from "@/components/fa-icon-server";
1211

12+
import { FernLinkTab } from "../FernLinkTab";
13+
1314
export function HeaderTabsList({
1415
tabs,
1516
children,
@@ -21,22 +22,23 @@ export function HeaderTabsList({
2122
<Tabs.TabsList>
2223
{tabs.map((tab) => (
2324
<Tabs.TabsTrigger key={tab.id} value={tab.id} asChild>
24-
<FernLink
25+
<FernLinkTab
2526
className={cn({ "opacity-50": tab.type !== "link" && tab.hidden })}
2627
href={
2728
tab.type === "link"
2829
? tab.url
2930
: slugToHref(hasRedirect(tab) ? tab.pointsTo : tab.slug)
3031
}
3132
scroll={true}
33+
id={tab.id}
3234
>
3335
{tab.type !== "link" && tab.authed ? (
3436
<Lock />
3537
) : (
3638
tab.icon && <FaIconServer icon={tab.icon} />
3739
)}
3840
<span className="truncate">{tab.title}</span>
39-
</FernLink>
41+
</FernLinkTab>
4042
</Tabs.TabsTrigger>
4143
))}
4244
{children}

packages/fern-docs/bundle/src/components/sidebar/SidebarTabsList.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TabChild, hasRedirect } from "@fern-api/fdr-sdk/navigation";
77
import { cn } from "@fern-docs/components";
88
import { slugToHref } from "@fern-docs/utils";
99

10-
import { FernLink } from "@/components/FernLink";
10+
import { FernLinkTab } from "@/components/FernLinkTab";
1111
import { FaIconServer } from "@/components/fa-icon-server";
1212

1313
export function SidebarTabsList({
@@ -21,7 +21,7 @@ export function SidebarTabsList({
2121
<Tabs.TabsList className="-my-2">
2222
{tabs.map((tab) => (
2323
<Tabs.TabsTrigger key={tab.id} value={tab.id} asChild>
24-
<FernLink
24+
<FernLinkTab
2525
className={cn(
2626
"min-h-8 lg:min-h-9",
2727
"hover:text-(color:--accent) rounded-2 group flex min-w-0 flex-1 select-none items-center justify-start py-2 text-base lg:px-3 lg:text-sm",
@@ -51,7 +51,7 @@ export function SidebarTabsList({
5151
<span className="truncate font-medium group-data-[state=active]:font-semibold">
5252
{tab.title}
5353
</span>
54-
</FernLink>
54+
</FernLinkTab>
5555
</Tabs.TabsTrigger>
5656
))}
5757
{children}

0 commit comments

Comments
 (0)