Sidebar (Presentation)
Standalone navigation sidebar with menus, groups, and adaptive layoutsView source →A 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
shellUsage
tsxAnatomy
Sidebar is a compound component with the following parts:
tsxRoot 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
tsxMenuSub 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.
tsxThin
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.
tsxSizes
Set size for sidebar density: 1 for compact interfaces, 2 for standard spacing.
Size 1
Compact density for information-dense layouts.
tsxSize 2
Standard density for most applications.
tsxVariants
Use the variant prop to set the sidebar container style.
Outline
Default bordered style providing clear visual boundaries.
tsxSoft
Subtle background for less prominent sidebars.
tsxSurface
Elevated surface for content-heavy UIs.
tsxGhost
Minimal style that blends with the background.
tsxMenu Variants
Use the menuVariant prop to control how menu item highlights appear.
Soft
Subtle background highlights on hover and active states.
tsxSolid
Bold filled highlights for maximum emphasis.
tsxColors
Use the color prop to set the accent color for active states and highlights.
tsxUse highContrast for increased color saturation:
tsxGroups
Use Sidebar.Group to organize related navigation items with optional labels.
tsxSub-menus
Use Sidebar.MenuSub for collapsible nested navigation. Automatically adapts: accordion in expanded mode, dropdown in thin mode.
tsxBadges
Add badges to menu buttons for notifications or status indicators.
Simple Badge
Pass a string for a simple badge:
tsxConfigured Badge
Pass an object for full badge customization:
tsxShortcuts
Display keyboard shortcuts on menu buttons:
tsxWith Routing
Use asChild to integrate with routing libraries like Next.js:
tsxWith Shell
When used inside Shell.Sidebar, the sidebar inherits the shell's state. Control the presentation prop based on shell mode:
tsxNote: The standalone Sidebar component does not automatically consume Shell context. Pass the presentation mode explicitly or use useShell() hook in a wrapper component.
Examples
Application Sidebar
Complete sidebar with header, grouped navigation, and footer:
tsxRail Sidebar
Compact icon-focused sidebar:
tsxAccessibility
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