Sidebar
A collapsible navigation panel that displays items with support for icons, badges, sections, role-based filtering, and tooltips in collapsed state.
Import
Usage
Basic sidebar with flat items
Sidebar with sections
Examples
Variant
Size
Radius
Item radius
With sections
With active item
Collapsed state
With back button
Active item styling
With badges
With tooltips (collapsed)
Role-based filtering
With footer
Disabled items
Custom styling
With custom link component
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | SidebarItem<T>[] | SidebarSection<T>[] | None | List of navigation items or sections |
activeKey | T | None | Key of currently active item |
onSelect | (item: SidebarItem<T>) => void | None | Callback when item is clicked |
isCollapsed | boolean | None | Controlled collapsed state |
onCollapseChange | (collapsed: boolean) => void | None | Callback when collapse state changes |
title | ReactNode | None | Sidebar header title |
onBack | () => void | None | Back button click handler |
backIcon | ReactNode | ArrowLeftIcon | Custom back button icon |
userRole | string | None | Role for filtering items |
footer | ReactNode | None | Footer content |
variant | "default" | "bordered" | "floating" | "ghost" | "default"* | Visual style |
size | "sm" | "md" | "lg" | "md"* | Size scale |
radius | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "full" | "none"* | Sidebar corner rounding |
itemRadius | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "full" | "md"* | Item corner rounding |
itemVariant | "solid" | "ghost" | "bordered" | "faded" | "underlined" | "ghost"* | Visual style for inactive items |
activeItemVariant | "solid" | "ghost" | "bordered" | "faded" | "underlined" | "solid"* | Visual style for the active item |
activeItemColor | "none" | "primary" | "secondary" | "danger" | "warning" | "success" | "primary"* | Color for the active item |
showTooltips | boolean | true* | Show tooltips in collapsed state |
tooltipPlacement | "top" | "bottom" | "left" | "right" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "left-start" | "left-end" | "right-start" | "right-end" | "right"* | Tooltip placement |
collapsible | boolean | true* | Whether the sidebar can be collapsed |
defaultCollapsed | boolean | false* | Initial collapsed state for uncontrolled usage |
showCollapseButton | boolean | true* | Whether the collapse button is shown |
linkComponent | React.ElementType | None | Custom link component (e.g., Next.js Link, TanStack Router Link). Replaces the native <a> tag. |
linkProps | Record<string, unknown> | None | Additional props passed to the custom link component (e.g., { prefetch: true }). Overwrites anchorProps when conflicting. |
headerClassName | string | None | Extra classes for header |
bodyClassName | string | None | Extra classes for navigation |
itemClassName | string | None | Extra classes for each item |
sectionLabelClassName | string | None | Extra classes for section labels |
footerClassName | string | None | Extra classes for footer |
className | string | None | Extra classes, merged with internal styles |
* Falls back through Global Configuration if not set. See below.
SidebarSection
| Prop | Type | Description |
|---|---|---|
id | T | Unique section identifier (required) |
label | ReactNode | Section display label |
items | SidebarItem<T>[] | Array of items in the section |
roles | string[] | Role strings for filtering |
disabled | boolean | Disables the entire section |
SidebarItem
| Prop | Type | Description |
|---|---|---|
id | T | Unique identifier (required) |
label | ReactNode | Display label (required) |
href | string | URL or path for navigation |
icon | ReactNode | Leading icon |
badge | ReactNode | Trailing badge content |
roles | string[] | Role strings for filtering |
disabled | boolean | Disables click interaction |
target | string | Link target attribute |
rel | string | Link rel attribute |
Global Configuration
Sidebar reads defaults from four places, in this order of precedence:
- Instance prop: set directly on
<Sidebar /> - Component config:
components.sidebarin yourashee.config - Theme default:
defaultVariant/defaultColor/defaultRadiusin yourashee.config - Built-in fallback: component's internal default values
Component config
Built-in fallbacks
Accessibility
- Uses native
<aside>and<nav>elements for proper semantics - Implements
focus-visiblerings for keyboard navigation - Disabled items prevent interaction and are properly announced
- Tooltips include proper ARIA attributes
- Collapsed state preserves navigation functionality
- Items remain keyboard accessible when collapsed
Notes
- Items Prop: The
itemsprop accepts either a flat array ofSidebarItemor an array ofSidebarSection. Flat items are automatically wrapped in a single section. - Sections: Use sections to group related items with optional section labels.
- Role-based Filtering: Items and sections can be filtered based on the current user's role via the
userRoleprop androlesarrays. - Collapsed State: When collapsed, the sidebar shows only icons and tooltips for better space efficiency.
- Tooltips: Tooltips are automatically shown for items when the sidebar is collapsed and
showTooltipsis enabled. - Back Button: The back button is displayed in the header when
onBackis provided. - Active Item: The active item is highlighted using the
activeItemVariant,activeItemColor, anditemVariantprops. - Custom Link Component: You can replace the default
<a>tag with any routing-library link component (e.g., Next.jsLink, TanStack RouterLink) using thelinkComponentprop. Additional props can be passed vialinkProps. All styles, interactions, and tooltips are preserved.