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.
Sidebar Examples
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
| Component | Description |
|---|---|
| SidebarProvider | Provides sidebar state (open, collapsed, mobile) via context |
| Sidebar | The sidebar container, supports side, variant, and collapsible |
| SidebarTrigger | A button that toggles the sidebar |
| SidebarHeader / SidebarFooter | Fixed sections at the top and bottom |
| SidebarContent | Scrollable middle section |
| SidebarGroup / SidebarGroupLabel / SidebarGroupContent | Groups related menu items |
| SidebarMenu / SidebarMenuItem / SidebarMenuButton | Renders the navigation menu |
| SidebarInset | The main content area next to the sidebar |
| SidebarRail | A draggable rail for resizing/toggling |
| useSidebar | Hook to access sidebar state from any child |