An app's side navigation: groups of links, sections that open, a sliding current-page highlight, and a collapse to icons.
$ pnpm dlx shadcn@latest add https://dashral.com/r/sidebar.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/sidebar.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/sidebarUsage
import Link from "next/link"
import { CreditCard, LayoutDashboard, Users } from "lucide-react"
import { Sidebar } from "@/components/dashral/sidebar"
<Sidebar
header={<Logo />}
items={[
{ label: "Overview", icon: <LayoutDashboard />, href: "/", active: pathname === "/" },
{ label: "Customers", icon: <Users />, href: "/customers", badge: 12 },
{ type: "group", label: "Settings", items: [{ label: "Billing", icon: <CreditCard />, href: "/billing" }] },
]}
linkAs={Link}
/>Examples
API reference
Sidebar
Also takes every prop of <aside>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
items | SidebarItem[]Required. Links ({ label, icon, href, active, badge, children }), groups ({ type: "group", label, items }) and separators. | — |
header | ReactNodeAt the top: a logo, a workspace switcher. | — |
footer | ReactNodeAt the bottom: the signed-in user, a help link. | — |
collapsed / defaultCollapsed / onCollapsedChange | booleanNarrowed to its icons. Controlled, or initial with the toggle changing it. | false |
collapsible | booleanThe collapse toggle at the bottom. | true |
linkAs | ElementTypeYour router's link, for items with href. | "a" |
aria-label | stringNames the navigation (translated by default). | "Navigation" |
classNames | { header, nav, footer, item }Classes for each part. | — |
className | stringExtra classes, merged with cn() so yours win. | — |
SidebarLink
= { label: string; icon?: ReactNode; href?: string; onSelect?: () => void; active?: boolean; badge?: ReactNode; disabled?: boolean; children?: SidebarLink[]; defaultOpen?: boolean }Keyboard
| Keys | Action |
|---|---|
| Tab | Move between the links |
| EnterorSpace | Follow a link, or open and close a section |
Accessibility
- A <nav> landmark, named by aria-label.
- The current page is aria-current="page"; a section's row is a button with aria-expanded, and a closed section is inert.
- Collapsed, every link keeps its name (and shows it in a tooltip); a section's row opens its links in a menu.
Motion
- The current page's highlight slides to it (--duration-considered); collapsing narrows the width and sections open on their height in CSS.