Navigation
Sidebar
Free25.5 KB gzippedApp side navigation. See SidebarProps and the parts (Sidebar.Header, .Body, .Section, .Item, .Group, .Footer, .Toggle).
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space and 1 more · Full report
Import
import { Sidebar } from "@vjdesigns/vjdesigns-ui";
Importing only Sidebar adds about 25.5 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
App navigation with sections, badges and collapsible groups. Sidebar.Toggle collapses it to icons, with tooltips. Use mode="overlay" to show it as a drawer on small screens.
Current page: dashboard
import { useState, type MouseEvent } from "react";
import {
BellIcon,
Box,
CalendarIcon,
FileIcon,
HelpIcon,
HomeIcon,
MailIcon,
SettingsIcon,
Sidebar,
Text,
UsersIcon,
} from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [active, setActive] = useState("dashboard");
const item = (id: string) => ({
href: `#${id}`,
active: active === id,
onClick: (event: MouseEvent<HTMLElement>) => {
event.preventDefault();
setActive(id);
},
});
return (
<Box border radius="lg" overflow="hidden" display="flex" surface="surface" style={{ width: "100%", height: "30rem" }}>
<Sidebar aria-label="Example app">
<Sidebar.Header>
<Text weight="black">Acme</Text>
<Sidebar.Toggle />
</Sidebar.Header>
<Sidebar.Body>
<Sidebar.Section>
<Sidebar.Item {...item("dashboard")} icon={<HomeIcon />}>
Dashboard
</Sidebar.Item>
<Sidebar.Item {...item("inbox")} icon={<MailIcon />} badge={3} badgeLabel="3 unread">
Inbox
</Sidebar.Item>
<Sidebar.Item {...item("alerts")} icon={<BellIcon />}>
Alerts
</Sidebar.Item>
</Sidebar.Section>
<Sidebar.Section heading="Workspace">
<Sidebar.Item {...item("team")} icon={<UsersIcon />}>
Team
</Sidebar.Item>
<Sidebar.Item {...item("calendar")} icon={<CalendarIcon />}>
Calendar
</Sidebar.Item>
<Sidebar.Group label="Documents" icon={<FileIcon />} defaultOpen>
<Sidebar.Item {...item("briefs")}>Briefs</Sidebar.Item>
<Sidebar.Item {...item("contracts")}>Contracts</Sidebar.Item>
</Sidebar.Group>
</Sidebar.Section>
</Sidebar.Body>
<Sidebar.Footer>
<Sidebar.Section>
<Sidebar.Item {...item("settings")} icon={<SettingsIcon />}>
Settings
</Sidebar.Item>
<Sidebar.Item {...item("help")} icon={<HelpIcon />}>
Help
</Sidebar.Item>
</Sidebar.Section>
</Sidebar.Footer>
</Sidebar>
<Box p={6} style={{ flex: 1 }}>
<Text weight="semibold">Current page: {active}</Text>
</Box>
</Box>
);
}
Collapsed
Collapsed to an icon rail, every item still has its name: it's shown as a tooltip on hover and focus, and remains the item's accessible name. Sidebar.Toggle is a named button that reports whether the sidebar is expanded.
Hover or tab through the rail to see the names.
import {
Box,
CalendarIcon,
HomeIcon,
MailIcon,
Sidebar,
Text,
} from "@vjdesigns/vjdesigns-ui";
export function Collapsed() {
return (
<Box border radius="lg" overflow="hidden" display="flex" surface="surface" style={{ width: "100%", height: "22rem" }}>
<Sidebar aria-label="Collapsed example" defaultCollapsed>
<Sidebar.Header>
<Sidebar.Toggle />
</Sidebar.Header>
<Sidebar.Body>
<Sidebar.Section>
<Sidebar.Item href="#example-collapsed" icon={<HomeIcon />} active>
Dashboard
</Sidebar.Item>
<Sidebar.Item href="#example-collapsed" icon={<MailIcon />} badge={3} badgeLabel="3 unread">
Inbox
</Sidebar.Item>
<Sidebar.Item href="#example-collapsed" icon={<CalendarIcon />}>
Calendar
</Sidebar.Item>
</Sidebar.Section>
</Sidebar.Body>
</Sidebar>
<Box p={6} style={{ flex: 1 }}>
<Text tone="muted">Hover or tab through the rail to see the names.</Text>
</Box>
</Box>
);
}
Accessibility
The sidebar is a navigation landmark named by aria-label. The active item is marked as the current page, badges are spoken through badgeLabel ("3 unread", not "3"), and each Sidebar.Group is a disclosure button that reports whether it's expanded.
Main content.
import {
BellIcon,
Box,
FileIcon,
HomeIcon,
Sidebar,
Text,
} from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Box border radius="lg" overflow="hidden" display="flex" surface="surface" style={{ width: "100%", height: "24rem" }}>
<Sidebar aria-label="Workspace">
<Sidebar.Body>
<Sidebar.Section heading="Projects" headingLevel={3}>
<Sidebar.Item href="#example-accessibility" icon={<HomeIcon />} active>
Overview
</Sidebar.Item>
<Sidebar.Item href="#example-accessibility" icon={<BellIcon />} badge={3} badgeLabel="3 unread">
Updates
</Sidebar.Item>
<Sidebar.Group label="Reports" icon={<FileIcon />}>
<Sidebar.Item href="#example-accessibility">Quarterly</Sidebar.Item>
<Sidebar.Item href="#example-accessibility">Annual</Sidebar.Item>
</Sidebar.Group>
</Sidebar.Section>
</Sidebar.Body>
</Sidebar>
<Box p={6} style={{ flex: 1 }}>
<Text tone="muted">Main content.</Text>
</Box>
</Box>
);
}
Translated
In Hebrew the sidebar moves to the right and its contents mirror. The collapse button's names come from the locale; the item labels are your own text.
תוכן ראשי.
import {
Box,
HomeIcon,
SettingsIcon,
Sidebar,
Text,
UsersIcon,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import he from "@vjdesigns/vjdesigns-ui/locales/he";
export function Translated() {
return (
<LocaleProvider locale="he" messages={he}>
<Box border radius="lg" overflow="hidden" display="flex" surface="surface" style={{ width: "100%", height: "22rem" }}>
<Sidebar aria-label="ניווט">
<Sidebar.Header>
<Text weight="black">אקמה</Text>
<Sidebar.Toggle />
</Sidebar.Header>
<Sidebar.Body>
<Sidebar.Section>
<Sidebar.Item href="#example-translated" icon={<HomeIcon />} active>
לוח בקרה
</Sidebar.Item>
<Sidebar.Item href="#example-translated" icon={<UsersIcon />}>
צוות
</Sidebar.Item>
<Sidebar.Item href="#example-translated" icon={<SettingsIcon />}>
הגדרות
</Sidebar.Item>
</Sidebar.Section>
</Sidebar.Body>
</Sidebar>
<Box p={6} style={{ flex: 1 }}>
<Text tone="muted">תוכן ראשי.</Text>
</Box>
</Box>
</LocaleProvider>
);
}
API reference
Sidebar
| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
aria-labelAccessible name of the navigation landmark. Use a different name for each | string | "Main navigation" |
mode
| "static""overlay" | "static" |
collapsedControlled collapsed (icon rail) state. Static mode only. | boolean | — |
defaultCollapsedInitial collapsed state when uncontrolled. | boolean | false |
onCollapsedChangeCalled with the next collapsed state (from | (collapsed: boolean) => void | — |
openOverlay mode: controlled open state of the drawer. | boolean | — |
defaultOpenOverlay mode: initial open state when uncontrolled. | boolean | false |
onOpenChangeOverlay mode: called with the next open state (close button, Escape, backdrop, or navigation). | (open: boolean) => void | — |
closeOnNavigateOverlay mode: close the drawer when a | boolean | true |
overlayLabelOverlay mode: the drawer dialog's accessible name. Defaults to the sidebar's | string | — |
sizeItem height and type size ( | "sm""md""lg" | "md" |
tooltipPlacementSide for rail tooltips. The default | TooltipPlacement | "end" |
Also accepts native <nav> attributes, plus className, style and ref.
Sidebar.Header
| Prop | Type | Default |
|---|---|---|
childrenBrand, workspace switcher, and usually a | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
Sidebar.Body
| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
Sidebar.Section
| Prop | Type | Default |
|---|---|---|
headingVisible group label, e.g. "Teams". The section becomes | ReactNode | — |
headingLevelRenders the heading as | 23456 | — |
children
| ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
Sidebar.Item
| Prop | Type | Default |
|---|---|---|
childrenRequiredThe visible label. It is the item's accessible name, including in rail mode (where it also appears as a tooltip). | ReactNode | — |
iconDecorative icon before the label. Required for a usable rail: it's all that shows when collapsed. | ReactNode | — |
activeMarks the current page: sets | boolean | false |
badgeA count (rendered with | SidebarBadgeValue | — |
badgeLabelScreen-reader text for the badge, e.g. "3 unread messages". Replaces the visible badge text in the accessible name. | string | — |
badgeToneBadge color. | "neutral""primary""accent""success""warning""danger""info" | "accent" |
disabledDisables the item. Buttons use the native | boolean | false |
hrefPass a URL to render the item as a link ( | string | — |
Also accepts native <button> attributes, plus className, style and ref.
Sidebar.Group
| Prop | Type | Default |
|---|---|---|
labelRequiredThe disclosure button's visible label, and its accessible name. | ReactNode | — |
iconDecorative icon before the label. Shown alone in rail mode. | ReactNode | — |
childrenNested | ReactNode | — |
openControlled open state. | boolean | — |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state. | (open: boolean) => void | — |
activeOne of the nested items is the current page. While the group is closed (or the sidebar is a rail), the button shows the active look so users can see where they are. It doesn't set | boolean | false |
badgeA count or short text on the group button, like | SidebarBadgeValue | — |
badgeLabelScreen-reader text for the badge. | string | — |
badgeToneBadge color. | "neutral""primary""accent""success""warning""danger""info" | "accent" |
disabledDisables the disclosure button. | boolean | false |
valueA stable key for the group. An uncontrolled group's open state is kept by key, so it survives a | string | — |
Also accepts native <li> attributes, plus className, style and ref.
Sidebar.Footer
| Prop | Type | Default |
|---|---|---|
childrenAccount, settings, or help links (a | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
Sidebar.Toggle
| Prop | Type | Default |
|---|---|---|
hrefPass a URL to render the control as a link ( | undefined | — |
disabledDisables the control. Buttons use the native | boolean | false |
loadingReplaces the icon with a spinner, sets | boolean | false |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl size. | "sm""md""lg""xs" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
collapseLabelAccessible name (and tooltip) while expanded. | string | "Collapse sidebar" |
expandLabelAccessible name (and tooltip) while collapsed. | string | "Expand sidebar" |
childrenCustom icon. Defaults to a chevron that points toward the collapse direction. | ReactNode | — |
Also accepts standard HTML attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Sidebar targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves through the items. It's a list of links, not a menu. |
| EnterSpace | Toggles a group, or the collapsed rail (Sidebar.Toggle). |
| Escape | Overlay mode: closes the sidebar. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Sidebar | navigation | aria-label |
| Item | link | aria-current="page" when active |
| Group button | button | aria-expanded, aria-controls |
| Badge | none | Spoken through badgeLabel ("3 unread") |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |