Skip to content
codefastlabs

Command Palette

Search for a command to run...

Source
Navigation

Sidebar

Composable application sidebar with collapsible groups, rail, and mobile sheet. Built for app shells.

Examples

Anatomy

How the parts nest — every slot the component exposes, in composition order.

SidebarProvider
├── Sidebar
│ └── SidebarContent
│ └── SidebarGroup
│ └── SidebarMenu
│ └── SidebarMenuItem
│ └── SidebarMenuButton
└── SidebarTrigger

Features

  • Persists the open/collapsed state in a sidebar_state cookie (7-day max-age), so a full page reload keeps the sidebar as the user left it.
  • Becomes a Sheet-based drawer below the sidebar breakpoint (48rem by default) — no separate mobile layout to build.
  • Move that breakpoint with @theme { --breakpoint-sidebar: 40rem; } in your stylesheet: the docked layout, the sidebar: variant it mints, and the switch to the sheet all follow the one value.

API reference

Props for each part of the component. All native element props are also forwarded.

SidebarProvider

Wraps the shell; owns collapse state and keyboard shortcut.

defaultOpenboolean

Whether the sidebar starts expanded.

Defaulttrue

openboolean

The controlled open (expanded) state.

onOpenChange(open: boolean) => void

Called when the open state changes.

shortcutKeystring | false

The key that toggles the sidebar together with ⌘ or Ctrl. false turns the shortcut off.

Default"b"

Sidebar

The panel: docked from the sidebar breakpoint up, a sheet below it.

side"left" | "right"

Which edge the sidebar sits on.

Default"left"

variant"sidebar" | "floating" | "inset"

How the docked panel is drawn.

Default"sidebar"

collapsible"offcanvas" | "icon" | "none"

How the docked panel collapses.

Default"offcanvas"

mobileTitlestring

The accessible name of the sheet it opens as below the breakpoint.

Default"Sidebar"

Sidebar parts

SidebarMenuButtonReactNode

A nav row; compose inside SidebarMenuItem / SidebarGroup.

SidebarTrigger—

Toggles the sidebar; place it in your main content.

Accessibility

Built to be keyboard-navigable and screen-reader friendly out of the box.

KeyFunction
⌘/Ctrl+BToggles the sidebar, except while typing in a field or when another handler already used the key. shortcutKey changes or turns it off.
TabMoves through the menu buttons.
EnterActivates the focused item.
  • Built as a nav landmark; the collapsed rail keeps icons reachable.
  • On mobile it becomes a sheet — ensure the trigger is always reachable.
  • Give icon-only collapsed items accessible names (tooltips or labels).

Guidelines

Conventions that keep usage consistent across an app.

Do

  • Use for app shells with persistent navigation.
  • Group links with labels and keep the list shallow.

Don’t

  • Don’t use a sidebar for a content site with few pages.
  • Don’t hide the toggle — users need a way back.

Explore further

Ready to integrate?

Follow the Getting Started guide to install @codefast/ui, or browse the full component gallery.