Skip to content

Sidebar

The app sidebar: collapsible to icons, a sheet on phones, with groups, menus, actions and badges.

A page-level item: the sidebar is fixed to the viewport and SidebarProvider is as tall as the page. To place one inside a box, as here, give the provider the class contents, then either use collapsible="none" or give the box contain-layout and the sidebar max-h-full. SidebarInset is a main element, so a page takes only one.

Collapsing to icons

The button above collapses the sidebar to its icons. On a phone it opens the sidebar as a sheet.

Navigation

Harbour studio
Workspace
  • 4
Money
  • 3

Submenus and row actions

Projects
Archive

Loading

Projects

Installation

npx shadcn@latest add @khaeli/sidebar

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0
  • @keyline-icons/react ^2.2.0
  • class-variance-authority ^0.7.1
  • motion ^12.23.12

Keyboard

Tab
Moves through the rows, their actions and the submenu links, in order. A disabled row is skipped. SidebarRail is not in the tab order.
EnterSpace
Activate the focused row or SidebarTrigger.
⌘ BCtrl + B
Collapses or expands the sidebar at once, with no animation. With several providers on a page, only the first one answers.
Escape
Closes the sheet the sidebar opens in on a phone and returns focus to the trigger. When focus is on a row that has a tooltip, the first press only dismisses the tooltip.

Accessible name

  • SidebarTrigger names itself "Hide sidebar" or "Show sidebar". The phone sheet is a dialog titled "Sidebar".
  • A row is named by its text. Keep the text in a span so it stays the name when the sidebar is collapsed to icons; tooltip shows it to sighted users then.
  • isActive is only a look. Mark the current page with aria-current="page" as well.
  • SidebarGroupAction and SidebarMenuAction are icon buttons: give each an aria-label that names its row or group.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/sidebar.json