Components
Nested Sidebar
A sidebar with expandable sections.
<NestedSidebar sections={sections} current="#hooks" />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/nested-sidebar.jsonimport { NestedSidebar } from "@/components/nested-sidebar"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
A sidebar of sections that expand and collapse. The section holding the current page starts open, and closed sections are taken out of the tab order.
import { NestedSidebar } from "@/components/nested-sidebar";
const sections = [
{ label: "Guides", items: [{ label: "Install", href: "/install" }, { label: "Theming", href: "/theming" }] },
{ label: "API", items: [{ label: "Hooks", href: "/hooks" }] },
];
export function DocsSidebar({ path }: { path: string }) {
return <NestedSidebar sections={sections} current={path} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
sections | { label, items: { label, href }[] }[] | The sections and their links. | |
current | string | The current page's href. | |
label | string | "Docs" | Accessible name of the nav. |
className | string | Classes for the root element. |
With reduced motion, sections open without sliding.