Dashral Pro is on the wayGet 30% off at launch

Dashral

Sidebar

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.json

Installation

$ pnpm dlx shadcn@latest add https://dashral.com/r/sidebar.json

Adds 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:

components.json
{
  "registries": {
    "@dashral": "https://dashral.com/r/{name}.json"
  }
}

Then add components by name:

$ pnpm dlx shadcn@latest add @dashral/sidebar

Usage

example.tsx
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

Sections that open

children make a row a section; the one with the current page opens on its own.

Collapsed to icons

defaultCollapsed: names in tooltips, and a section's links in a menu beside it.

API reference

Sidebar

Also takes every prop of <aside>(opens in a new tab).

PropTypeDefault
itemsSidebarItem[]

Required. Links ({ label, icon, href, active, badge, children }), groups ({ type: "group", label, items }) and separators.

—
headerReactNode

At the top: a logo, a workspace switcher.

—
footerReactNode

At the bottom: the signed-in user, a help link.

—
collapsed / defaultCollapsed / onCollapsedChangeboolean

Narrowed to its icons. Controlled, or initial with the toggle changing it.

false
collapsibleboolean

The collapse toggle at the bottom.

true
linkAsElementType

Your router's link, for items with href.

"a"
aria-labelstring

Names the navigation (translated by default).

"Navigation"
classNames{ header, nav, footer, item }

Classes for each part.

—
classNamestring

Extra 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

KeysAction
TabMove between the links
EnterorSpaceFollow 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.