cnippet/ui
  1. ui
  2. layout
  3. sidebar

layout

Sidebar

A collapsible app navigation panel with groups, menus, badges and sub-menus that turns into a sheet on mobile. Copy-paste ready.

Installation

Usage

Wrap your layout in SidebarProvider, then put the Sidebar and your page (SidebarInset) side by side.

Anatomy

Good to know

  • Cmd+B (Ctrl+B on Windows and Linux) toggles the sidebar.
  • Below the md breakpoint the sidebar opens as a Sheet from SidebarTrigger instead of sitting beside the page.
  • The open state is saved in a sidebar_state cookie for a week. Read it on the server and pass it as defaultOpen so the first render matches what the user left it at.
  • With collapsible="icon", the collapsed sidebar shows only icons. Give each SidebarMenuButton a tooltip so its label still appears on hover.
  • The sidebar is position: fixed to the viewport. The examples here sit in a box with transform-gpu, which makes that box the containing block so the demo stays inside it. You don't need that in a real app shell.
  • useSidebar() returns state, open, setOpen, openMobile, setOpenMobile, isMobile and toggleSidebar for custom controls.

API Reference

SidebarProvider

Set --sidebar-width and --sidebar-width-icon in style to change the widths (defaults 16rem and 3rem).

SidebarMenuButton

SidebarMenuSubButton

Renders an <a> by default. Takes isActive, size ("sm" \| "md") and render.

Examples

Inset with sub-menus

Docs-style navigation: each section is a Collapsible with nested links, and the page sits inset beside the sidebar.

Floating, right side

A details panel on the right with a search field that filters its menu.