Skip to Content
zjkm-ui
Components

Nested Sidebar

A sidebar with expandable sections.

Props
<NestedSidebar sections={sections} current="#hooks" />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/nested-sidebar.json
import { 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

PropTypeDefaultDescription
sections{ label, items: { label, href }[] }[]The sections and their links.
currentstringThe current page's href.
labelstring"Docs"Accessible name of the nav.
classNamestringClasses for the root element.

With reduced motion, sections open without sliding.

On this page