Sidebar
App navigation: a named landmark with groups and items (href or a router link), the current page marked with aria-current, collapsing to an icon rail with tooltips (or hiding, with collapse="hide") and opening in a drawer on narrow screens. The items scroll in a ScrollArea; a SidebarGroup with collapsible folds its items under its label, like a docs section (open, defaultOpen, onOpenChange). Agents collapse and expand it by name. A SidebarTrigger toggles it from elsewhere, like a Topbar, through its controller; useSidebarState wires both and remembers the state.
Example
Installation
class-variance-authority@0.7.1lucide-reactUsage
density="compact" makes the sidebar compact (items, spacing, type, width, rail and drawer) without changing the page, and density="default" keeps it roomy inside a compact page. groupGap (--sidebar-group-gap) and groupHeaderHeight (--sidebar-group-header-height) tighten the space between groups and the height of their labels or triggers: "compact", or a length or var(); the properties also work in CSS on the sidebar or any ancestor.
API reference
SidebarTrigger
| Prop | Type | Default |
|---|---|---|
controllerrequiredThe controller passed to the Sidebar it toggles. | SidebarController | – |
collapsedThe sidebar's state, from `collapsed`/`onCollapsedChange`, for `aria-expanded` and the right name. | boolean | – |
labels | Partial<SidebarLabels> | – |
narrowQueryMatch the Sidebar's. On narrow screens the trigger opens the Sidebar's drawer instead of collapsing it; give the Sidebar `trigger={false}` (or `narrowTrigger={false}`) so it doesn't render a drawer button of its own. | string | defaultNarrowQuery |
Also takes Button except size, aria-label, onClick.
SidebarGroup
| Prop | Type | Default |
|---|---|---|
labelShown above the items and names their list. Leave it out for items that need no heading, like the first ones. | string | – |
tone`muted` quiets the group's items, like sections on their way out; the current page keeps its fill. | "default" | "muted" | "default" |
collapsibleFolds the items under the label, which becomes a button with a chevron, like a docs section. Needs a `label`. In the icon rail the items always show, since the rail has no labels to press. | boolean | false |
openWhether a collapsible group is open; pair it with `onOpenChange`. | boolean | – |
defaultOpenWhether a collapsible group starts open. Open by default. | boolean | true |
onOpenChange | CollapsibleProps["onOpenChange"] | – |
childrenrequired | ReactNode | – |
Also takes <div> attributes except children.
SidebarItem
| Prop | Type | Default |
|---|---|---|
icon | ReactNode | – |
current | boolean | false |
badge | ReactNode | – |
render | ReactElement<Record<string, unknown>> | – |
childrenrequired | string | – |
Also takes LinkProps except children, current, variant, render.
Sidebar
| Prop | Type | Default |
|---|---|---|
labelrequired | string | – |
densityThe sidebar's own density, apart from the page's: `"compact"` tightens its items, spacing and type and narrows it, `"default"` keeps the default density inside a compact page. Follows the page when left out. | "default" | "compact" | – |
groupGapThe space between groups (`--sidebar-group-gap`). `"default"` is `gap-group`, `"compact"` is `gap-items`; a length or `var()` sets it exactly. Lists of collapsible groups keep 1px unless it's a length. | SidebarGroupSpacing | – |
groupHeaderHeightThe height of the groups' headers (`--sidebar-group-header-height`). `"default"` keeps a label's line and a collapsible group's trigger at the control height; `"compact"` tightens the label's line and makes the trigger `control-height-sm`; a length or `var()` gives both that height. | SidebarGroupSpacing | – |
collapsed | boolean | – |
defaultCollapsed | boolean | false |
onCollapsedChange | (collapsed: boolean, details: ChangeDetails<SidebarCollapsedChangeReason>) => void | – |
collapsible | boolean | true |
collapseWhat collapsing does on wide screens: `rail` keeps the items as icons with tooltips; `hide` slides the sidebar away, for items without icons, like a docs sidebar. Hidden, it has no toggle of its own, so pair it with a SidebarTrigger elsewhere. | "rail" | "hide" | "rail" |
trigger`false` when a SidebarTrigger elsewhere, like in a Topbar's `leading`, takes the place of the sidebar's own buttons: the collapse toggle in its header and, on narrow screens, the drawer button. | boolean | true |
narrowTriggerWhether the sidebar renders its drawer button on narrow screens. Follows `trigger` by default. | boolean | trigger |
controller | SidebarController | – |
narrowQuery | string | defaultNarrowQuery |
header | ReactNode | – |
footer | ReactNode | – |
labels | Partial<SidebarLabels> | – |
className | string | – |
childrenrequired | ReactNode | – |
Other exports
createSidebarControllersidebardefaultNarrowQueryPanelIconsetSidebarDrawerOpensidebarLabelsuseNarrowuseSidebarDrawerOpenSidebarRailContextuseSidebarStatetype SidebarCollapsedChangeReasontype SidebarControllertype SidebarOptionstype SidebarLabelstype SidebarTriggerPropstype SidebarGroupPropstype SidebarItemPropstype SidebarStatetype SidebarStateOptionstype SidebarDensitytype SidebarGroupSpacingtype SidebarPropsAccessibility
- A named navigation landmark; the current item has aria-current=page.
- Collapses to an icon rail with tooltips, and to a drawer on narrow screens.
- The items scroll in a ScrollArea named by the sidebar's label: the wheel, touch, keyboard and find in page work as on any page.
- A collapsible group's label is a UI SDK Collapsible trigger: a button with aria-expanded that Enter and Space toggle, its items a list named by the label. Closed, its links leave the tab order.
Agent actions
Agents collapse and expand the sidebar by its label, open or close a collapsible group by its label (setOpen), and follow its items by name.
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.