Skip to content

Commit

Permalink
fix: navigation subpages
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-mesnil committed Oct 17, 2023
1 parent 014d6ea commit 1102c3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion website/app/components/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Layout = ({ children, params }: LayoutProps) => {

return (
<Documentation.Layout>
<Sidebar menu={pages} />
<Sidebar isSubPage menu={pages} />
<div>
<Text py="3xl" variant="h1">
{getName(id)}
Expand Down
6 changes: 4 additions & 2 deletions website/build-app/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { getName } from '@/build-app/utils/transform-name'

type SidebarProps = {
menu: PageTree
isSubPage?: boolean
}

export const Sidebar = ({ menu }: SidebarProps) => {
export const Sidebar = ({ isSubPage, menu }: SidebarProps) => {
const currentRoute = usePathname()

return (
Expand All @@ -38,10 +39,11 @@ export const Sidebar = ({ menu }: SidebarProps) => {
<Flex as="ul" direction="column" gap="lg">
{pages.map(({ id, name, parent: pageParent }) => {
const href = `/${parent}/${pageParent ? `${pageParent}/` : ''}${id}`
const isCurrent = isSubPage ? currentRoute.startsWith(href) : currentRoute === href

return (
<li key={`sidebar_${category}_page_${id}`}>
<S.Link aria-current={currentRoute === href ? 'page' : undefined} href={href}>
<S.Link aria-current={isCurrent ? 'page' : undefined} href={href}>
{name || getName(id)}
</S.Link>
</li>
Expand Down

0 comments on commit 1102c3b

Please sign in to comment.