Primitives

Sidebar

A composable sidebar built from several small components. Supports collapsible groups, a mobile sheet, keyboard shortcuts, and an inset content area via SidebarProvider.


Dashboard
Main content area. Toggle the sidebar or expand a group above.

Installation

# The component is already installed at:
# src/components/ui/shadcn/sidebar.tsx

Usage

import {
  Sidebar,
  SidebarContent,
  SidebarInset,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
  SidebarTrigger,
} from '@/components/ui/shadcn/sidebar'

export function SidebarDemo() {
  return (
    <SidebarProvider>
      <Sidebar>
        <SidebarContent>
          <SidebarMenu>
            <SidebarMenuItem>
              <SidebarMenuButton asChild>
                <a href="#">Home</a>
              </SidebarMenuButton>
            </SidebarMenuItem>
          </SidebarMenu>
        </SidebarContent>
      </Sidebar>
      <SidebarInset>
        <SidebarTrigger />
        <p>Main content</p>
      </SidebarInset>
    </SidebarProvider>
  )
}

Embedding in a fixed-height container

The sidebar uses fixed positioning by default so it can span the full viewport. To confine it inside a bordered demo box, wrap it in a relative container and pass className="absolute h-full" to Sidebar, as shown in the example above.

Components

ComponentDescription
SidebarProviderProvides sidebar state (open, collapsed, mobile) via context
SidebarThe sidebar container, supports side, variant, and collapsible
SidebarTriggerA button that toggles the sidebar
SidebarHeader / SidebarFooterFixed sections at the top and bottom
SidebarContentScrollable middle section
SidebarGroup / SidebarGroupLabel / SidebarGroupContentGroups related menu items
SidebarMenu / SidebarMenuItem / SidebarMenuButtonRenders the navigation menu
SidebarInsetThe main content area next to the sidebar
SidebarRailA draggable rail for resizing/toggling
useSidebarHook to access sidebar state from any child
Previous
Sheet