Sidebar
Feature-rich collapsible sidebar with provider, menus, groups, and sub-navigation.
Default
A sidebar with grouped navigation items wrapping a main content area.
Installation
npx visor add sidebarThis copies two files into your project:
components/ui/sidebar/sidebar.tsx— the componentcomponents/ui/sidebar/sidebar.module.css— the styles
Usage
import {
SidebarProvider, Sidebar, SidebarHeader, SidebarContent,
SidebarGroup, SidebarGroupLabel, SidebarGroupContent,
SidebarMenu, SidebarMenuItem, SidebarMenuButton,
SidebarFooter, SidebarInset,
} from '@/components/ui/sidebar/sidebar';
<SidebarProvider>
<Sidebar>
<SidebarHeader>
<h2>My App</h2>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Navigation</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton isActive>Dashboard</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
</Sidebar>
<SidebarInset>
<main>Page content</main>
</SidebarInset>
</SidebarProvider>API Reference
SidebarProps
No props data available for “sidebar”.
Icon rail under an app bar
A rail is a Sidebar collapsed to icons. Give it position="contained" so it lays out inside its parent and sits under an app bar; the default fixed pins it to the viewport at full height and would cover the bar. Override the provider's min-height (it defaults to 100svh) with style or className.
<SidebarProvider defaultOpen={false} style={{ minHeight: 0, flex: 1 }}>
<Sidebar collapsible="icon" position="contained">
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton asChild tooltip="Inbox">
<Link href="/inbox"><Tray /></Link>
</SidebarMenuButton>
<SidebarMenuBadge aria-hidden="true" />
</SidebarMenuItem>
</SidebarMenu>
</Sidebar>
</SidebarProvider>asChildrenders the child (a Next<Link>, an<a>) as the item through Radix Slot, keeping the button treatment anddata-*hooks.SidebarMenuBadgestays a sibling in the<li>, so it positions the same way.tooltipis a string, or an object ofTooltipContentprops (children,side,container). It shows when the sidebar is collapsed to icons (collapsible="icon") and forcollapsible="none"rails (a static rail has no collapsed state, so passingtooltipis the opt-in). It never shows on mobile or in an expanded sidebar. A string also becomes the button'saria-labelwhile the rail is icon-only, unless you setaria-labeloraria-labelledbyyourself.- The tooltip portals into the
Sidebarelement, so a class-scoped theme on an ancestor reaches it. Passcontainerto override.SidebarProviderincludes aTooltipProvider. keyboardShortcutonSidebarProvider(defaulttrue) controls Cmd/Ctrl+B. The binding is skipped, with nopreventDefault, while onlycollapsible="none"sidebars are mounted. Passfalseto never bind it.
Sub-components
| Component | Element | Purpose |
|---|---|---|
SidebarProvider | <div> | Context provider managing state, mobile detection, and keyboard shortcuts. |
Sidebar | <div> | The sidebar container with side, variant, and collapsible props. |
SidebarTrigger | <button> | Button that toggles sidebar open/closed. |
SidebarRail | <button> | Clickable rail at the sidebar edge for toggling. |
SidebarInset | <main> | Main content area companion to the sidebar. |
SidebarHeader | <div> | Top section for branding or user info. |
SidebarFooter | <div> | Bottom section for settings or user actions. |
SidebarContent | <div> | Scrollable content area between header and footer. |
SidebarGroup | <div> | Visual grouping of related menu items. |
SidebarGroupLabel | <div> | Heading label for a group. |
SidebarGroupAction | <button> | Action button in a group header. |
SidebarGroupContent | <div> | Content container within a group. |
SidebarMenu | <ul> | List container for menu items. |
SidebarMenuItem | <li> | Individual menu list item. |
SidebarMenuButton | <button> | Interactive button with active state and tooltip support. |
SidebarMenuAction | <button> | Secondary action (e.g., more options) on a menu item. |
SidebarMenuBadge | <div> | Badge indicator (e.g., notification count). |
SidebarMenuSub | <ul> | Nested sub-menu list. |
SidebarMenuSubItem | <li> | Sub-menu list item. |
SidebarMenuSubButton | <a> | Interactive link/button within a sub-menu item. |
SidebarSeparator | <hr> | Horizontal divider between sections. |
Accessibility
- Toggle keyboard shortcut:
Cmd+B(macOS) /Ctrl+B(Windows/Linux). Turn it off withkeyboardShortcut={false}; it is skipped forcollapsible="none". - Menu items use semantic
<ul>/<li>structure. SidebarMenuButtonsupportsisActiveforaria-currentindication.- Collapsible modes (offcanvas, icon-only) preserve accessible labels:
SidebarMenuButton'stooltipstring names the button while the label is hidden.
Section Intro
Marketing section opener with a mono uppercase eyebrow, display-font heading, and optional lede paragraph. Eyebrow color tracks a live-rewritten CSS custom property for runtime brand-accent binding.
ThemeSwitcher
Fixed-position pill switcher for theme and dark/light mode, with an extras slot for hosting devtools chrome. Built with CSS Modules — copy it into your project and own it completely.