UI

Sidebar

Vertical navigation column with workspace switching, live search, reorderable favorites, collapsible groups, and a compact icon rail.

import { Sidebar } from '@uthereal/ui/sidebar'

Sidebar playground

Loading interactive preview…

Overview

Sidebar renders a standalone vertical navigation column without an outer app shell, header bar, or page canvas. It supports an optional workspace switcher, live substring search, pinned favorites that reorder by pointer drag or keyboard, collapsible navigation groups with one level of nested sub-items, footer rows, and a compact icon rail.

Use Sidebar as the primary vertical navigation inside an application layout. Use Tabs for sibling views of one entity, Breadcrumb for path hierarchy above a page, and Progress for single-document heading outlines.

Usage

'use client'
import { Sidebar } from '@uthereal/ui/sidebar'

export function AppSidebar({
  activeId,
  onOpen,
}: {
  activeId: string
  onOpen: (href: string) => void
}) {
  return (
    <Sidebar
      label="Workspace navigation"
      activeId={activeId}
      workspaces={[
        { id: 'northwind', name: 'Northwind', plan: 'Business', icon: 'globe' },
        {
          id: 'fieldwork',
          name: 'Fieldwork Labs',
          plan: 'Team',
          icon: 'sparkles',
        },
      ]}
      searchable
      favorites={[
        {
          id: 'roadmap',
          label: 'Q4 roadmap',
          icon: 'calendar',
          href: '/roadmap',
        },
        {
          id: 'audit',
          label: 'Component audit',
          icon: 'list-checks',
          href: '/audit',
        },
      ]}
      groups={[
        {
          id: 'workspace',
          label: 'Workspace',
          items: [
            {
              id: 'inbox',
              label: 'Inbox',
              icon: 'mail',
              badge: 4,
              href: '/inbox',
            },
            {
              id: 'projects',
              label: 'Projects',
              icon: 'folder',
              children: [
                {
                  id: 'checkout',
                  label: 'Checkout redesign',
                  href: '/projects/checkout',
                },
                {
                  id: 'system',
                  label: 'Design system',
                  href: '/projects/system',
                },
              ],
            },
          ],
        },
      ]}
      footerItems={[
        {
          id: 'settings',
          label: 'Settings',
          icon: 'settings',
          action: 'open_settings',
        },
      ]}
      onNavigate={(href) => onOpen(href)}
      onAction={(action, id) => console.log(action, id)}
    />
  )
}

Pass activeId, collapsed, or workspaceId with their on*Change callbacks to control state from your application. Omit them to let Sidebar manage state from defaultActiveId, defaultCollapsed, and defaultWorkspaceId. Link rows report navigation through onNavigate(href, id) and action rows report through onAction(action, id).

Examples

Use <SchemaPlayground /> above to try multi-workspace switching, live search filtering, reorderable favorites, width, railWidth, collapsible, recipe, theme, motion, and dir. The examples below show rail and tree modes without workspace chrome.

Rail and tree modes

Compare a compact icon rail (defaultCollapsed: true) with hover/focus tooltips and unread indicator dots against an expanded navigation tree with nested sub-items and rolling badges.

Rail folding, search, and favorites

CapabilityBehavior
Icon rail foldOne MotionValue writes --ui-sidebar-fold directly to the column so width interpolates via CSS calc() without row re-renders.
Rail tooltipsCollapsed icons render native <button> or <a> controls wrapped in a Tooltip showing the label and unread badge count.
Live searchFilters favorites, group items, nested sub-items, and footer rows in place. Matching slices highlight inside <mark>.
Reorderable favoritesVertical pointer drag (4 px threshold) and Alt+ArrowUp/Alt+ArrowDown reorder favorites. Pauses while collapsed or filtering.

API reference

Serializable arguments and defaults come directly from sidebarConfigSchema.

ArgumentType / defaultDescription
labelstringDefault: "Sidebar navigation"Names the navigation landmark for assistive technology.
workspacesSidebarWorkspace[]—Workspace choices for the switcher (id, name, plan, icon or avatarSrc); up to 20 with unique ids. Omitted renders no switcher.
defaultWorkspaceIdstring—The initially chosen workspace; edits do not reset a mounted instance.
searchablebooleanDefault: falseShows a search field that filters favorites, groups and footer rows live; Escape clears it.
searchPlaceholderstringDefault: "Search"Placeholder in the search field.
favoritesSidebarFavorite[]—Pinned rows at the top (id, label, icon, badge, href or action); up to 20 with unique ids.
favoritesLabelstringDefault: "Favorites"Section title over the favorites.
reorderableFavoritesbooleanDefault: trueDrag on the Y axis or Alt+ArrowUp/Alt+ArrowDown reorders the favorites, announced politely.
groupsSidebarGroup[]Default: []Labelled sections of nav items (up to 12 groups of 40), each optionally collapsible with nested sub-items one level deep (up to 20).
footerItemsSidebarItem[]—Rows pinned below the scroll area; up to 8.
defaultActiveIdstring—The initially active row; edits do not reset a mounted instance.
collapsiblebooleanDefault: trueThe sidebar can fold into a compact icon rail.
defaultCollapsedbooleanDefault: falseStart as the icon rail; edits do not reset a mounted instance.
widthintegerDefault: 272Expanded width in px (180 to 400; default 272).
railWidthintegerDefault: 64Collapsed icon rail width in px (48 to 88; default 64).
shortcutbooleanDefault: trueBracket toggles the rail when focus is outside inputs, menus and dialogs.
collapseLabelstringDefault: "Collapse sidebar"Accessible name of the collapse toggle when expanded, e.g. 'Collapse sidebar'.
expandLabelstringDefault: "Expand sidebar"Accessible name of the collapse toggle when collapsed, e.g. 'Expand sidebar'.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeSidebarTheme—Color mode, accent, and tokens, including row, mark and switcher geometry. See Theming.
motionnone | subtle | expressiveDefault: "subtle"The width spring between full and rail, group disclosure heights, the active highlight and badge rolls. none is immediate; system reduced motion jumps geometry and crossfades labels.
motionOptionsSidebarMotionOptions—Fine-grained overrides, such as widthDuration for the fold spring; merges over the motion preset.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

Nested item fields

TypeKey fields
SidebarWorkspaceid, name, plan?, icon?, avatarSrc?
SidebarFavoriteid, label, icon?, badge? (0–999), href? or action? (mutually exclusive)
SidebarGroupid, label, collapsible (default true), defaultOpen (default true), items
SidebarItemid, label, icon?, badge?, href? or action?, disabled, children (max 20)
SidebarSubItemid, label, icon?, badge?, href? or action?, disabled

React integration

PropPurpose
activeId, onActiveIdChangeControl or observe the active row ID.
collapsed, onCollapsedChangeControl or observe the folded icon-rail state.
workspaceId, onWorkspaceChangeControl or observe the selected workspace ID.
onFavoritesReorder(order)Called with favorite IDs in display order after a drag or keyboard reorder completes.
onNavigate(href, id)Called when a link row (href) activates.
onAction(action, itemId)Called when an action row (action) activates.
headerSlot, footerSlotOptional React content rendered below the switcher and below footerItems when expanded.
renderIcon(name, context)Replace named icons; context provides size, slot, and id. Wrapped in IconSlot.
presetApplication defaults overridden by explicit instance props.
tokens--ui-* CSS variables applied after the typed theme on the root and portalled overlays.
ref, className, styleForwarded to the root navigation container.

Keyboard & accessibility

KeyInteraction
[Toggles the icon rail while visible on screen. Ignored in inputs, textareas, selects, contentEditable, menus, and dialogs.
Alt+ArrowUp, Alt+ArrowDownMoves the focused favorite up or down one position and restores focus to the moved row.
EscapeClears the search field when non-empty.
TabMoves focus across the workspace switcher, search field, rows, group toggles, and fold toggle.
Enter, SpaceActivates the focused link, action row, group toggle, workspace switcher, or fold toggle.

Sidebar renders a single role="navigation" landmark named by label. The active destination carries aria-current="page". Collapsible group headings render native <button> triggers with aria-expanded and aria-controls, while folded groups set inert so focus skips hidden rows. The workspace switcher uses @zag-js/menu radio items in both expanded and collapsed rail modes. Numeric badges pair RollingNumber with visually hidden plain text so screen readers announce one number. A polite role="status" live region announces rail collapse/expand, workspace switches, and favorite reorder positions.

In RTL (dir="rtl"), logical CSS properties, tree connectors, disclosure chevrons, the panel glyph, switcher menu alignment, and rail tooltip placement mirror automatically. Under forced-colors: active, rows, toggles, and active highlights use ButtonText, Highlight, and HighlightText.

Motion and theming

Column width springs between width and railWidth on the critically damped smooth spring (400 ms, bounce 0) through one MotionValue (motionOptions.widthDuration overrides the settle duration in ms). Collapsible group heights animate on smooth, the active row highlight glides between rows via layoutId (scoped per instance with useId()) on the morph spring (0.42 s, bounce 0.16), and numeric badges roll through RollingNumber.

  • motion="none" makes width changes, group toggles, active highlights, label visibility, badge updates, and hover states immediate (0 ms).
  • prefers-reduced-motion: reduce jumps width, group height, and active highlight placement immediately while preserving a 120 ms opacity crossfade on labels and badges.

theme accepts mode, accent, global tokens from core and shape plus borderStrong, borderSubtle, and surfaceSunken, and component geometry tokens: rowHeight (32 px, 40 px on coarse pointers), rowRadius (8 px), markSize (32 px), markRadius (9 px), toggleSize (32 px), switcherRadius (10 px), and iconSize (16 px). Supply shared defaults with UtherealProvider.

Composition

In agent compositions, Sidebar is a leaf component. Host state persists at /components/instance-<id>/activeId, collapsed, workspaceId, and favoritesOrder, each reconciled when edits add or remove rows or workspaces. Every item action is collected and validated against host-registered actions. See Building with agents.

{
  "type": "Sidebar",
  "props": {
    "label": "App navigation",
    "defaultActiveId": "overview",
    "groups": [
      {
        "id": "main",
        "label": "General",
        "items": [
          {
            "id": "overview",
            "label": "Overview",
            "icon": "globe",
            "href": "/"
          },
          {
            "id": "inbox",
            "label": "Inbox",
            "icon": "mail",
            "badge": 3,
            "href": "/inbox"
          }
        ]
      }
    ]
  },
  "children": []
}

On this page