Sidebar

Collapsible sidebar navigation component with a built-in toggle button. Supports controlled and uncontrolled modes, configurable widths, and smooth transition animations.

Uncontrolled Sidebar

Preview
Click the arrow to collapse

Controlled Sidebar

Preview

Default Collapsed

Preview
Starts collapsed

Props

PropTypeDefaultDescription
collapsedboolean-Controlled collapsed state. When provided, the component becomes fully controlled.
defaultCollapsedbooleanfalseInitial collapsed state for uncontrolled usage.
onCollapsedChange(collapsed: boolean) => void-Callback fired when the collapsed state changes.
widthstring"260px"Width of the sidebar when expanded.
collapsedWidthstring"60px"Width of the sidebar when collapsed.
childrenReactNode-Sidebar content, typically navigation links or menu items.
classNamestring-Additional CSS classes for the aside element.

Accessibility

  • Renders as a semantic <aside> element.
  • The toggle button includes an aria-label that updates based on the collapsed state ("Expand sidebar" / "Collapse sidebar").
  • The data-collapsed attribute is set on the aside element for CSS-based styling hooks.
  • Navigation links inside the sidebar should use proper anchor tags or accessible link components.
  • The transition uses CSS transition-all for smooth width changes.