Sidebar (Presentation)
Standalone navigation sidebar with menus, groups, and adaptive layoutsA presentational sidebar component for building navigation menus. Works standalone or inside Shell.Sidebar for layout integration. Adapts between rail (icon-focused) and panel (full-width) presentations.
Installation
Usage
Anatomy
Sidebar is a compound component with the following parts:
Root Props
The Root component provides context and styling for all child components.
Content Props
Scrollable container for navigation content.
Header Props
Container for logo, app name, and header controls.
Footer Props
Container for user profile, settings, and footer content.
MenuButton Props
Interactive button for navigation items.
BadgeConfig
MenuSub Props
Container for collapsible sub-menus. Renders as accordion in expanded mode, dropdown in thin mode.
Presentation
Use the presentation prop to control the sidebar layout mode.
Expanded
Full-width panel layout with text labels. Ideal for main navigation.
Thin
Compact rail layout with icons and minimal text. Icons stack vertically, text appears below icons in smaller font. Sub-menus render as dropdowns instead of accordions.
Sizes
Set size for sidebar density: 1 for compact interfaces, 2 for standard spacing.
Size 1
Compact density for information-dense layouts.
Size 2
Standard density for most applications.
Variants
Use the variant prop to set the sidebar container style.
Outline
Default bordered style providing clear visual boundaries.
Soft
Subtle background for less prominent sidebars.
Surface
Elevated surface for content-heavy UIs.
Ghost
Minimal style that blends with the background.
Menu Variants
Use the menuVariant prop to control how menu item highlights appear.
Soft
Subtle background highlights on hover and active states.
Solid
Bold filled highlights for maximum emphasis.
Colors
Use the color prop to set the accent color for active states and highlights.
With menuVariant="solid", a gray sidebar fills its active items with step 12 on its own:
Groups
Use Sidebar.Group to organize related navigation items with optional labels.
Sub-menus
Use Sidebar.MenuSub for collapsible nested navigation. Automatically adapts: accordion in expanded mode, dropdown in thin mode.
Badges
Add badges to menu buttons for notifications or status indicators.
Simple Badge
Pass a string for a simple badge:
Configured Badge
Pass an object for full badge customization:
Shortcuts
Display keyboard shortcuts on menu buttons:
With Routing
Use asChild to integrate with routing libraries like Next.js:
With Shell
Sidebar does not read the Shell's state by itself. Inside Shell.Sidebar, read the Shell's sidebar mode with Shell.useSidebarMode() in a small wrapper, and pass it to presentation:
Shell.useSidebarMode() returns sidebarMode ('collapsed', 'thin' or 'expanded') and setSidebarMode. The setter acts like a Trigger: it calls the Shell Sidebar's onStateChange with reason: 'toggle', and a controlled Sidebar changes only when you pass the new state. It must be called inside Shell.Root.
Examples
Application Sidebar
Complete sidebar with header, grouped navigation, and footer:
Rail Sidebar
Compact icon-focused sidebar:
Accessibility
Sidebar provides comprehensive accessibility through semantic HTML and ARIA attributes.
Keyboard Navigation
- Tab - Move focus between interactive elements
- Enter / Space - Activate focused menu button
- Arrow Down - Move to next menu item
- Arrow Up - Move to previous menu item
- Arrow Right - Expand sub-menu (accordion mode)
- Arrow Left - Collapse sub-menu (accordion mode)
- Escape - Close dropdown (thin mode sub-menus)
ARIA Attributes
role="menu"on menu containersrole="menuitem"on interactive itemsaria-current="page"on active itemsaria-haspopup="menu"on sub-menu triggersaria-expandedon collapsible sectionsrole="navigation"witharia-labelon content container
Screen Readers
- Semantic structure with proper heading hierarchy via group labels
- Active state announcements for current page
- Sub-menu expansion state announcements
- Badge content included in accessible name
Changelog
Added
- Initial release of standalone Sidebar (Presentation) component
- Compound component API with Root, Content, Header, Footer, Menu, MenuItem, MenuButton, MenuSub, MenuSubTrigger, MenuSubContent, Group, GroupLabel, GroupContent, Separator
- Two presentation modes: expanded (panel) and thin (rail)
- Automatic sub-menu behavior adaptation: accordion in expanded, dropdown in thin
- Badge support with string or full configuration object
- Keyboard shortcut display
- Integration with routing via asChild
- Full keyboard navigation
- Responsive size prop support
Changed
- Decoupled from Shell context for standalone usage
- Simplified API focused on presentation rather than state management
- Solid gray menu items fill with step 12 automatically, and labels read the strong ink
Removed
highContrastonSidebar.Rootand inBadgeConfig. Delete it; gray and text contrast are now automatic
© 2026 Kushagra Dhawan. Licensed under MIT. GitHub.