Skip to content

Commit

Permalink
fix docs link active state
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed May 15, 2024
1 parent 548c704 commit 7288e42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion site/components/SiteLayout/NavigationLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import Link from 'next/link'

export function NavigationLink({
href,
activePathnames,
children,
}: {
href: string
activePathnames?: string[]
children: React.ReactNode
}) {
const currentPathname = usePathname()
const isCurrent = currentPathname.startsWith(href)
const isCurrent = activePathnames
? activePathnames.some((pathname) => currentPathname.startsWith(pathname))
: currentPathname.startsWith(href)

return (
<Link
Expand Down
7 changes: 6 additions & 1 deletion site/components/SiteLayout/SiteLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export function SiteLayout({
style={{ width: undefined, height: 'var(--font-size-body-1)' }}
/>
</a>
<NavigationLink href="/docs/getting-started">Docs</NavigationLink>
<NavigationLink
href="/docs/getting-started"
activePathnames={['/docs', '/packages']}
>
Docs
</NavigationLink>
<NavigationLink href="/changelog">Changelog</NavigationLink>
</header>
{sidebar}
Expand Down

0 comments on commit 7288e42

Please sign in to comment.