Sidebar

Navigation sidebar component with support for nested items, collapsible sections, icons, and collapsed state. Ideal for application layouts.

Basic Sidebar

Main Content Area

Content appears here alongside the sidebar navigation.

With Sections

Organized Navigation

Sections group related navigation items. Some sections are collapsible and can start collapsed.

Nested Navigation

Hierarchical Navigation

Click parent items to expand/collapse nested children. Great for complex navigation structures.

Collapsed State

Expanded (w-70)

Responsive Sidebar

Collapsed sidebar shows only icons. Hover over icons to see tooltips with labels.

Width Variants

Small (w-60)

Medium (w-70, Default)

Large (w-80)

Right Position

Main Content

Sidebar can be positioned on the right side. Border appears on the left instead of right.

Props

Sidebar

NameTypeDefaultDescription
sectionsSidebarSection[]-Array of sections with grouped items
itemsSidebarItem[]-Array of items (alternative to sections)
collapsedbooleanfalseWhether sidebar is collapsed (shows icons only)
onCollapse(collapsed: boolean) => void-Callback when collapse state changes
position'left' | 'right''left'Sidebar position
width'sm' | 'md' | 'lg''md'Width of expanded sidebar
classNamestring-Additional CSS classes

SidebarItem Type

NameTypeDefaultDescription
id*string-Unique identifier for the item
label*string-Display text for the item
hrefstring-Link destination (omit for parent items)
iconReactNode-Icon to display before label
activeboolean-Whether this is the current page
childrenSidebarItem[]-Nested child items

SidebarSection Type

NameTypeDefaultDescription
id*string-Unique identifier for the section
titlestring-Section header title
items*SidebarItem[]-Items in this section
collapsibleboolean-Whether section can be collapsed
defaultCollapsedboolean-Whether section starts collapsed

Usage Guidelines

When to use

  • For primary navigation in web applications
  • When you have multiple navigation items that need persistent visibility
  • For hierarchical navigation with parent/child relationships
  • In dashboard layouts where navigation needs to be always accessible

Best practices

  • Use icons consistently across all navigation items
  • Keep navigation item labels short and descriptive
  • Group related items into sections for better organization
  • Mark the current page with the active state
  • Limit nesting to 2 levels to maintain simplicity
  • Use collapsed state on smaller screens to save space

Accessibility

  • ARIA role: navigation with aria-label
  • Semantic HTML: Uses aside and nav elements
  • Current page: Marked with aria-current="page"
  • Keyboard accessible: Tab and arrow key navigation
  • Focus indicators: Visible focus rings on all interactive elements
  • Collapsed state: Icons include title attribute for tooltips

Do's and Don'ts

Do

  • Group related navigation items into sections
  • Use icons to help users quickly identify menu items
  • Highlight the current page with the active state
  • Keep navigation labels concise and clear
  • Provide a collapsed state for responsive layouts
Content

Don't

  • Don't use long navigation labels that get truncated
  • Don't nest navigation more than 2 levels deep
  • Don't mix items with icons and items without icons
  • Don't forget to mark the current page as active
  • Don't use sidebar for temporary or contextual navigation

Related Components

Resources