Sidebar

Sidebar

A collapsible navigation panel that displays items with support for icons, badges, sections, role-based filtering, and tooltips in collapsed state.


Import

tsx
import { Sidebar } from "asheeui";

Usage

Basic sidebar with flat items

tsx
import { Sidebar } from "asheeui";
const items = [
{ id: "dashboard", label: "Dashboard" },
{ id: "users", label: "Users" },
{ id: "settings", label: "Settings" },
];
export default function Basic() {
return <Sidebar items={items} title="Navigation" className="w-64" />;
}

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

Disabled items

Custom styling


Props

PropTypeDefaultDescription
itemsSidebarItem<T>[] | SidebarSection<T>[]NoneList of navigation items or sections
activeKeyTNoneKey of currently active item
onSelect(item: SidebarItem<T>) => voidNoneCallback when item is clicked
isCollapsedbooleanNoneControlled collapsed state
onCollapseChange(collapsed: boolean) => voidNoneCallback when collapse state changes
titleReactNodeNoneSidebar header title
onBack() => voidNoneBack button click handler
backIconReactNodeArrowLeftIconCustom back button icon
userRolestringNoneRole for filtering items
footerReactNodeNoneFooter 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
showTooltipsbooleantrue*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
collapsiblebooleantrue*Whether the sidebar can be collapsed
defaultCollapsedbooleanfalse*Initial collapsed state for uncontrolled usage
showCollapseButtonbooleantrue*Whether the collapse button is shown
linkComponentReact.ElementTypeNoneCustom link component (e.g., Next.js Link, TanStack Router Link). Replaces the native <a> tag.
linkPropsRecord<string, unknown>NoneAdditional props passed to the custom link component (e.g., { prefetch: true }). Overwrites anchorProps when conflicting.
headerClassNamestringNoneExtra classes for header
bodyClassNamestringNoneExtra classes for navigation
itemClassNamestringNoneExtra classes for each item
sectionLabelClassNamestringNoneExtra classes for section labels
footerClassNamestringNoneExtra classes for footer
classNamestringNoneExtra classes, merged with internal styles

* Falls back through Global Configuration if not set. See below.

SidebarSection

PropTypeDescription
idTUnique section identifier (required)
labelReactNodeSection display label
itemsSidebarItem<T>[]Array of items in the section
rolesstring[]Role strings for filtering
disabledbooleanDisables the entire section

SidebarItem

PropTypeDescription
idTUnique identifier (required)
labelReactNodeDisplay label (required)
hrefstringURL or path for navigation
iconReactNodeLeading icon
badgeReactNodeTrailing badge content
rolesstring[]Role strings for filtering
disabledbooleanDisables click interaction
targetstringLink target attribute
relstringLink rel attribute

Global Configuration

Sidebar reads defaults from four places, in this order of precedence:

  1. Instance prop: set directly on <Sidebar />
  2. Component config: components.sidebar in your ashee.config
  3. Theme default: defaultVariant / defaultColor / defaultRadius in your ashee.config
  4. Built-in fallback: component's internal default values

Component config

ts
// ashee.config.ts
import type { ExternalConfig } from "asheeui";
export const config: ExternalConfig = {
components: {
sidebar: {
size: "md",
variant: "default",
radius: "none",
itemRadius: "md",
itemVariant: "ghost",
activeItemVariant: "solid",
activeItemColor: "primary",
showTooltips: true,
tooltipPlacement: "right",
collapsible: true,
defaultCollapsed: false,
showCollapseButton: true,
},
},
};

Built-in fallbacks

ts
{
size: "md",
variant: "default",
radius: "none",
itemRadius: "md",
itemVariant: "ghost",
activeItemVariant: "solid",
activeItemColor: "primary",
showTooltips: true,
tooltipPlacement: "right",
tooltipVariant: "solid",
tooltipColor: "secondary",
animated: true,
collapsible: true,
defaultCollapsed: false,
showCollapseButton: true,
}

Accessibility

  • Uses native <aside> and <nav> elements for proper semantics
  • Implements focus-visible rings 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 items prop accepts either a flat array of SidebarItem or an array of SidebarSection. 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 userRole prop and roles arrays.
  • 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 showTooltips is enabled.
  • Back Button: The back button is displayed in the header when onBack is provided.
  • Active Item: The active item is highlighted using the activeItemVariant, activeItemColor, and itemVariant props.
  • Custom Link Component: You can replace the default <a> tag with any routing-library link component (e.g., Next.js Link, TanStack Router Link) using the linkComponent prop. Additional props can be passed via linkProps. All styles, interactions, and tooltips are preserved.
Previous

← Select

Next

Spinner →