Skip to content
Eskais UI

Navigation

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

npx shadcn@latest add @eskais/sidebar
npm packagesclass-variance-authority@0.7.1lucide-react

Usage

Import
import { createSidebarController, sidebar } from "@/components/ui/sidebar-primitive"import {  defaultNarrowQuery,  PanelIcon,  setSidebarDrawerOpen,  SidebarTrigger,  sidebarLabels,  useNarrow,  useSidebarDrawerOpen,} from "@/components/ui/sidebar-trigger"import { SidebarGroup, SidebarItem, SidebarRailContext } from "@/components/ui/sidebar-items"import { useSidebarState } from "@/components/ui/use-sidebar-state"import {  createSidebarController,  Sidebar,  SidebarGroup,  SidebarItem,  sidebarLabels,  SidebarTrigger,  useSidebarState,} from "@/components/ui/sidebar"

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

PropTypeDefault
controllerrequiredThe controller passed to the Sidebar it toggles.SidebarController–
collapsedThe sidebar's state, from `collapsed`/`onCollapsedChange`, for `aria-expanded` and the right name.boolean–
labelsPartial<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.stringdefaultNarrowQuery

Also takes Button except size, aria-label, onClick.

SidebarGroup

PropTypeDefault
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.booleanfalse
openWhether a collapsible group is open; pair it with `onOpenChange`.boolean–
defaultOpenWhether a collapsible group starts open. Open by default.booleantrue
onOpenChangeCollapsibleProps["onOpenChange"]–
childrenrequiredReactNode–

Also takes <div> attributes except children.

SidebarItem

PropTypeDefault
iconReactNode–
currentbooleanfalse
badgeReactNode–
renderReactElement<Record<string, unknown>>–
childrenrequiredstring–

Also takes LinkProps except children, current, variant, render.

Sidebar

PropTypeDefault
labelrequiredstring–
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–
collapsedboolean–
defaultCollapsedbooleanfalse
onCollapsedChange(collapsed: boolean, details: ChangeDetails<SidebarCollapsedChangeReason>) => void–
collapsiblebooleantrue
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.booleantrue
narrowTriggerWhether the sidebar renders its drawer button on narrow screens. Follows `trigger` by default.booleantrigger
controllerSidebarController–
narrowQuerystringdefaultNarrowQuery
headerReactNode–
footerReactNode–
labelsPartial<SidebarLabels>–
classNamestring–
childrenrequiredReactNode–

Other exports

createSidebarControllersidebardefaultNarrowQueryPanelIconsetSidebarDrawerOpensidebarLabelsuseNarrowuseSidebarDrawerOpenSidebarRailContextuseSidebarStatetype SidebarCollapsedChangeReasontype SidebarControllertype SidebarOptionstype SidebarLabelstype SidebarTriggerPropstype SidebarGroupPropstype SidebarItemPropstype SidebarStatetype SidebarStateOptionstype SidebarDensitytype SidebarGroupSpacingtype SidebarProps

Accessibility

  • 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.