Skip to content

Layout

SideNav

Collapsible side navigation with Section, Item, and Heading parts.

import { SideNav } from '@var-ui/react';

SideNav

Persistent side navigation with sticky header/footer zones around a scrollable middle. Compose with SideNav.Heading, SideNav.Section, and SideNav.Item (link via href or button via onClick). Optional collapsible icon-only mode and resizable width. Items render React Aria Link, so href honours RouterProvider for client-side routing.

Examples

Default

Brand in header, then a section of items.

Demo.tsxTSX
import { SideNav } from '@var-ui/react';

<SideNav header={<SideNav.Heading heading="Acme" />}>
  <SideNav.Section title="Main">
    <SideNav.Item label="Dashboard" href="/" selected />
  </SideNav.Section>
</SideNav>

Sections

Group related destinations with multiple SideNav.Sections — each can take title, subtitle, and several SideNav.Items.

Demo.tsxTSX
import { SideNav } from '@var-ui/react';

<SideNav header={<SideNav.Heading heading="Acme" subheading="Workspace" />}>
  <SideNav.Section title="Main">
    <SideNav.Item label="Dashboard" href="/" selected />
    <SideNav.Item label="Projects" href="/projects" />
  </SideNav.Section>
  <SideNav.Section title="Team" subtitle="Shared">
    <SideNav.Item label="Members" href="/members" />
    <SideNav.Item label="Billing" href="/billing" />
  </SideNav.Section>
</SideNav>

Collapsible sections

collapsible renders a section as a native <details> disclosure. defaultOpen sets where it starts. In React, open and onOpenChange control it. To remember what the reader opened and closed across page loads, give the SideNav a persistKey:

TSX
<SideNav persistKey="docs-sidebar">
  <SideNav.Section title="Guides" collapsible>
    …
  </SideNav.Section>
</SideNav>

State goes to localStorage under that key. Sections are told apart by their id, or else their title. The section holding the current page (aria-current="page") always starts open. Astro’s SideNav takes the same persistKey. The helper behind both is persistDisclosures(root, key) from @var-ui/core/shared/disclosureState, for plain HTML.

Props

Accessibility

The root is a nav landmark (label defaults to "Side navigation"). Selected items set aria-current="page". In collapsed icon-only mode, item labels surface via tooltips and the collapse control uses "Collapse navigation" / "Expand navigation". Nested collapsible items expose expand/collapse buttons and a role="group" submenu.