Installation
Theme
Mode

Navigation

Sidebar

The primary navigation rail for an app — a workspace switcher and search up top, grouped menus with icons, expandable submenus and count badges in the middle, an account menu at the foot. Collapses to a 64px icon rail to reclaim space, with tooltips standing in for labels, and remembers its collapsed and expanded-group state across visits.

$npx shadcn@latest add @orbit/sidebar

Overview

A live sidebar inside an app frame. Click the panel icon (or the right edge) to collapse to icons, expand a menu group, or press ⌘/Ctrl+B while focus is in the rail. Collapsed and expanded-group state persist to localStorage.

Anatomy

A fixed header and footer bracket a scrolling content area. Each menu item is an icon, a label, and an optional badge or disclosure chevron; nested items sit indented on a hairline guide, each marked with a dot that tints when active. A parent whose child is selected keeps a tinted icon — the active trail — so you stay oriented even collapsed.

Menu item & submenu — chevron rotates, the branch sits on a guide, leaves can carry a count pill.

Collapsing

The whole rail animates between 264 and 64 pixels. Collapsed, labels give way to centered icons, group labels become dividers, badges shrink to dots, and hovering an icon reveals its label. Each instance below is independently live.

Expanded264px
Collapsed to iconsdefaultCollapsed

Composition

The sidebar is assembled from parts, so variants are compositions: leave out <SidebarFooter> for no footer, skip badge props to drop the pills, or pass defaultCollapsed to start as an icon rail. Every instance stays fully interactive.

No footeromit <SidebarFooter>
No badgesomit badge props
Starts collapseddefaultCollapsed

Props

Navigation items render as any element you like — pass render={<Link href=…/>} and the item merges its styling, active state, and aria-current into your router link.

PropTypeDefaultDescription
<Sidebar> collapsedbooleanControlled collapsed state; pair with onCollapsedChange.
<Sidebar> defaultCollapsedbooleanfalseStart as a 64px icon rail (uncontrolled).
<Sidebar> defaultOpenGroupsstring[][]Submenu ids that start expanded.
<Sidebar> collapsiblebooleantrueSet false for a fixed rail — no toggle, shortcut, or rail handle.
<Sidebar> storageKeystring | false"sidebar"localStorage namespace for `…-collapsed` and `…-expanded`; false disables persistence.
<SidebarMenuButton> iconReactNodeLeading 18×18 icon, drawn with currentColor so it follows the active tint.
<SidebarMenuButton> activebooleanfalseCurrent destination — brand-tinted row, sets aria-current="page".
<SidebarMenuButton> activeTrailbooleanfalseParent of the active item: emphasized label, tinted icon, no fill.
<SidebarMenuButton> badge / badgeAccentReactNode / booleanCount pill (accent = brand tint); collapses to a dot on the icon.
<SidebarMenuButton> tooltipstringCollapsed hover-tooltip label; defaults to string children.
<SidebarMenuButton> renderReactElementRender as a custom element, e.g. render={<Link href=…/>}; props are merged.
<SidebarSubmenu> idstringStable id keying the group's expanded state and its persistence.
<SidebarSubmenuItem> active / renderboolean / ReactElementNested row with indent guide and dot; same render-prop contract.
PartscomponentsSidebarHeader, SidebarContent, SidebarFooter, SidebarGroup(Label), SidebarMenu(Item), SidebarMenuBadge, SidebarSubmenuTrigger/Content, SidebarTrigger, SidebarRail, useSidebar().

Usage

Do

Group by purpose

Three to seven items per labeled group. Long, flat lists are slow to scan and easy to lose your place in.

Don’t

Nest more than two levels

A sidebar is for top-level navigation. Deep, arbitrary hierarchy belongs in a Tree or on a dedicated page.

Do

Keep the active item obvious

One selected destination at a time, clearly tinted, so people always know where they are in the app.

Don’t

Bury primary nav when collapsed

Collapse to icons to save space, but keep every destination one click or hover away — never inside a hidden menu.

Keyboard & accessibility

The content area is a semantic <nav>; items are real buttons or your own links, so Tab, Enter, and Space work natively. Active items set aria-current, submenu triggers set aria-expanded and aria-controls, closed submenus are inert so hidden links never take focus, and collapsed items keep their labels for screen readers.

ClickSelect an item / toggle a group
⌘ / Ctrl + BCollapse or expand the rail
TabMove focus through items
Enter / SpaceActivate the focused item
Drag edgeToggle via the rail handle
HoverReveal an icon’s label (collapsed)