Skip to content
UI

Search docs

Search components and documentation

New
Menu

Sidebar

A composable, themeable app-shell sidebar for building dashboards.

Installation

npx logic2b@latest add sidebar

Usage

Wrap your layout in SidebarProvider, place Sidebar and SidebarInset as siblings inside it, and use SidebarTrigger to toggle. State persists across reloads via a cookie and can be toggled with /Ctrl + B.

import {
  Sidebar,
  SidebarContent,
  SidebarHeader,
  SidebarInset,
  SidebarProvider,
  SidebarTrigger,
} from "@/components/ui/sidebar"

export function AppLayout() {
  return (
    <SidebarProvider>
      <Sidebar>
        <SidebarHeader>My App</SidebarHeader>
        <SidebarContent>{/* SidebarGroup, SidebarMenu... */}</SidebarContent>
      </Sidebar>
      <SidebarInset>
        <header>
          <SidebarTrigger />
        </header>
        {/* page content */}
      </SidebarInset>
    </SidebarProvider>
  )
}

Sidebar takes side (left | right), variant (sidebar | floating | inset) and collapsible (offcanvas | icon | none). On narrow viewports it renders as a Sheet automatically. Read the current state (state, open, isMobile, toggleSidebar) with the useSidebar() hook from any descendant.

API

Prop Type Default
defaultOpen (SidebarProvider) boolean — uncontrolled initial open state true
open / onOpenChange (SidebarProvider) boolean / (open: boolean) => void — controlled state
side (Sidebar) left | right left
variant (Sidebar) sidebar | floating | inset sidebar
collapsible (Sidebar) offcanvas | icon | none offcanvas
tooltip (SidebarMenuButton) string | TooltipContent props — shown when collapsed to icons

SidebarTrigger is a Button that calls toggleSidebar(); it forwards all button props.

Examples

Icon rail

Floating variant

Accessibility

  • The whole sidebar can be toggled from the keyboard with /Ctrl + B, in addition to the SidebarTrigger button.
  • SidebarTrigger renders a labelled button (sr-only “Toggle Sidebar”) wired to toggleSidebar().
  • On mobile the sidebar becomes a Sheet, inheriting its focus trap and Esc-to-close behavior.
  • When collapsed to icon, add a tooltip to each SidebarMenuButton so the destination stays discoverable.