Nav
Sidebar navigation: an icon rail, a switcher, and lists of links that drill in or open as folders
Overview
Nav builds sidebars. NavRail holds an app’s largest sections as icons, and NavPanel beside it holds the current section’s pages, with a NavSwitcher in its header. Every row goes to a page. When one list can’t hold them all, a row drills in or expands.
Which One to Use
| You want to | Use | For example | Not for |
|---|---|---|---|
| Go to a page | A row in a group | Dashboard, Indicators | Actions, such as Log out: use a Dropdown Menu |
| Switch to another object, like a project, that the current section belongs to | NavSwitcher | Another project | Filtering a page: use a Select |
| Navigate into a sub-section with its own pages, where other rows in the current section stop mattering | Drill in | A policy, an agent’s run, an app’s Settings pages | A few views of one screen: use Tabs |
| Browse pages grouped by topic | Expand | A docs site’s folders, at any depth | A sub-section people work inside: drill in |
| Move between an app’s largest sections | NavRail | Projects, Agents, Library | An app with one section |
Usage
Import the parts:
import {
NavDrill,
NavDrillLevel,
NavList,
NavListExpandable,
NavListExpandableContent,
NavListExpandableTrigger,
NavListGroup,
NavListItem,
NavListSeparator,
NavPanel,
NavRail,
NavRailItem,
NavSwitcher,
} from "@eqtylab/equality";A rail beside a panel, with a switcher in the panel’s header and the rows below:
const projectOptions = projects.map((p) => ({ value: p.id, label: p.name }));
<div style={{ display: "flex", height: "100vh" }}>
<NavRail aria-label="Main">
<NavRailItem icon={<Folder />} label="Projects" href="/projects" current />
<NavRailItem icon={<Bot />} label="Agents" href="/agents" />
</NavRail>
<NavPanel
aria-label={`Project: ${project.name}`}
header={
<NavSwitcher
label={project.name}
noun="project"
collection="projects"
options={projectOptions}
value={project.id}
onValueChange={switchProject}
/>
}
>
<NavList>
<NavListGroup label="Project">
<NavListItem
label="Dashboard"
prefix={<LayoutGrid />}
href="/"
current
/>
</NavListGroup>
</NavList>
</NavPanel>
<main>…</main>
</div>;Groups
Give each group an optional label. A separator sets off a different kind of group, like settings at the foot. Mark the current page with current.
<NavList>
<NavListGroup label="Project">
<NavListItem label="Dashboard" prefix={<LayoutGrid />} href="/" current />
<NavListItem label="Indicators" prefix={<Activity />} href="/indicators" />
</NavListGroup>
<NavListGroup label="Applied Policies">
<NavListItem
label="EU AI Act"
prefix={<BookOpen />}
href="/policies/eu-ai-act"
/>
</NavListGroup>
<NavListSeparator />
<NavListGroup>
<NavListItem
label="Project Settings"
prefix={<Settings />}
href="/settings"
/>
</NavListGroup>
</NavList>Links and Routers
href makes a plain link. With a router, pass its link through asChild, so the page doesn’t reload. A drill row needs neither. Set current from the route.
<NavListItem label="Indicators" current={pathname === "/indicators"} asChild>
<Link to="/indicators" />
</NavListItem>target="_blank" opens the row in a new tab, with a ↗.
<NavListItem
label="Status Page"
href="https://status.eqtylab.io"
target="_blank"
/>Prefix and Suffix
prefix takes an icon. suffix takes a status or count as Badge size="sm", and screen readers read it with the label.
<NavListItem
label="Applied Policies"
prefix={<BookOpen />}
suffix={<Badge size="sm">2</Badge>}
href="/policies"
/>Switcher
NavSwitcher goes in the panel’s header and shows the current item’s name. Picking another item calls onValueChange. Keep the reader on the same page in the new item, such as Indicators. If they were inside a policy, take them to the new item’s top level instead: that policy belongs to the old item. action adds a command at the foot of the list.
const projectOptions = projects.map((p) => ({ value: p.id, label: p.name }));
<NavSwitcher
label={project.name}
noun="project"
collection="projects"
options={projectOptions}
value={project.id}
onValueChange={switchProject}
action={{ label: "Create Project", onSelect: openCreateProject }}
/>;When the List Fails to Load
Pass error and onRetry, and the list offers Retry: Couldn't load {collection}. with no options, or Some {collection} couldn't be loaded. over a partial list. Pass retrying while it reloads.
const projects = projectsQuery.data ?? [];
const projectOptions = projects.map((p) => ({ value: p.id, label: p.name }));
<NavSwitcher
{...props}
options={projectOptions}
error={projectsQuery.isError}
retrying={projectsQuery.isFetching}
onRetry={() => projectsQuery.refetch()}
/>;Drill-in
A row with drill opens the NavDrillLevel with that value. A level with a parent gets a ‹ row that goes back. Levels are direct children of NavDrill. Put the list on a background colour, like a panel or sheet, or the levels show through as they slide.
Uncontrolled
Set the first level with defaultValue. Use it where the URL doesn’t change, like a popover or sheet.
<NavList>
<NavDrill defaultValue="project">
<NavDrillLevel value="project">
<NavListGroup label="Applied Policies">
<NavListItem
label="EU AI Act"
prefix={<BookOpen />}
drill="eu-ai-act"
/>
</NavListGroup>
</NavDrillLevel>
<NavDrillLevel value="eu-ai-act" parent="project" label="EU AI Act">
<NavListGroup>
<NavListItem
label="Controls"
prefix={<Layers />}
href="/policies/eu-ai-act/controls"
/>
</NavListGroup>
</NavDrillLevel>
</NavDrill>
</NavList>Controlled by the URL
In an app, set value from the URL, so Back and bookmarks open the right level. onValueChange gets the level a click asks for: navigate there.
const { policy } = useParams();
const navigate = useNavigate();
function openLevel(level) {
navigate(level === "project" ? "/project" : `/policies/${level}`);
}
<NavDrill value={policy ?? "project"} onValueChange={openLevel}>
…
</NavDrill>;Expandable Groups
NavListExpandable is a folder. Put it in a NavListGroup, or inside another folder. A folder opens itself when a row inside it becomes current.
<NavListGroup>
<NavListExpandable defaultOpen>
<NavListExpandableTrigger label="Getting Started" />
<NavListExpandableContent>
<NavListItem label="Installation" href="/installation" current />
<NavListItem label="Theming" href="/theming" />
</NavListExpandableContent>
</NavListExpandable>
</NavListGroup>Nested Folders
Folders nest to any depth. Each level indents, so long labels cut off sooner.
<NavListExpandable defaultOpen>
<NavListExpandableTrigger label="Deployment" />
<NavListExpandableContent>
<NavListItem label="Quick Start" href="/deployment/quick-start" />
<NavListExpandable defaultOpen>
<NavListExpandableTrigger label="Baremetal" />
<NavListExpandableContent>
<NavListItem
label="K3s CoCo"
href="/deployment/baremetal/k3s-coco"
current
/>
</NavListExpandableContent>
</NavListExpandable>
</NavListExpandableContent>
</NavListExpandable>Folders in a Drill-in
Inside NavDrill, give each folder a value, unique within its level. The folder then stays open or closed when the reader drills away and comes back. Without a value, it forgets when its level rebuilds.
<NavDrillLevel value="project">
<NavListGroup>
<NavListExpandable value="reports">
<NavListExpandableTrigger label="Reports" />
<NavListExpandableContent>…</NavListExpandableContent>
</NavListExpandable>
</NavListGroup>
</NavDrillLevel>Examples
App Sidebar
The sidebar from Usage in full, with router links and a policy level that follows the URL.
const { projectId, policyId } = useParams();
const { pathname } = useLocation();
const navigate = useNavigate();
const base = `/projects/${projectId}`;
const policy = policies.find((item) => item.id === policyId);
const projectOptions = projects.map((p) => ({ value: p.id, label: p.name }));
function goToLevel(level) {
navigate(level === "project" ? base : `${base}/policies/${level}`);
}
<div style={{ display: "flex", height: "100vh" }}>
<NavRail aria-label="Main">
<NavRailItem icon={<Folder />} label="Projects" current asChild>
<Link to="/projects" />
</NavRailItem>
<NavRailItem icon={<Bot />} label="Agents" asChild>
<Link to="/agents" />
</NavRailItem>
</NavRail>
<NavPanel
aria-label={
policy ? `Applied Policy: ${policy.name}` : `Project: ${project.name}`
}
header={
<NavSwitcher
label={project.name}
noun="project"
collection="projects"
options={projectOptions}
value={project.id}
onValueChange={(id) => navigate(`/projects/${id}`)}
/>
}
>
<NavList>
<NavDrill value={policy?.id ?? "project"} onValueChange={goToLevel}>
<NavDrillLevel value="project">
<NavListGroup label="Project">
<NavListItem
label="Dashboard"
prefix={<LayoutGrid />}
current={pathname === base}
asChild
>
<Link to={base} />
</NavListItem>
</NavListGroup>
<NavListGroup label="Applied Policies">
{policies.map((item) => (
<NavListItem
key={item.id}
label={item.name}
prefix={<BookOpen />}
drill={item.id}
/>
))}
</NavListGroup>
</NavDrillLevel>
{policy && (
<NavDrillLevel
value={policy.id}
parent="project"
label={policy.name}
backLabel={`${policy.name}, back to ${project.name}`}
>
<NavListGroup>
<NavListItem label="Controls" prefix={<Layers />} asChild>
<Link to={`${base}/policies/${policy.id}/controls`} />
</NavListItem>
</NavListGroup>
</NavDrillLevel>
)}
</NavDrill>
</NavList>
</NavPanel>
<main>…</main>
</div>;Docs Sidebar
Rows built from a tree of folders and pages. Folders around the current row open themselves. @eqtylab/docs builds its sidebar this way.
function Rows({ nodes, top = false }) {
const { pathname } = useLocation();
return nodes.map((node) => {
const prefix = top && node.icon ? <Icon icon={node.icon} /> : undefined;
const suffix = node.badge && <Badge size="sm">{node.badge}</Badge>;
return node.children ? (
<NavListExpandable key={node.id}>
<NavListExpandableTrigger
label={node.label}
prefix={prefix}
suffix={suffix}
/>
<NavListExpandableContent>
<Rows nodes={node.children} />
</NavListExpandableContent>
</NavListExpandable>
) : (
<NavListItem
key={node.id}
label={node.label}
href={node.href}
current={node.href === pathname}
prefix={prefix}
suffix={suffix}
/>
);
});
}
<NavList>
<NavListGroup>
<Rows nodes={tree} top />
</NavListGroup>
</NavList>;Under a Sticky Header
The rail and panel pin to the top of the viewport as the page scrolls. Under a sticky header, set --eq-nav-offset to the header’s height, a length such as 64px, on the element that wraps the rail and panel, and they pin below it instead. Don’t set it on :root: a Sheet holding the sidebar on a phone would inherit it and push the list down.
<>
<header style={{ position: "sticky", top: 0, height: 64 }}>…</header>
<div style={{ display: "flex", "--eq-nav-offset": "64px" }}>
<NavRail aria-label="Main">…</NavRail>
<NavPanel aria-label={`Project: ${project.name}`} header={<NavSwitcher … />}>
…
</NavPanel>
<main>…</main>
</div>
</>Navigation in a Sheet
On a phone, put the whole sidebar in a Sheet from the left: the rail and panel side by side, the switcher in the panel’s header. Close the sheet when the route changes. Give it a hidden title. Set minWidth: 0 so the sheet fits the list.
const { pathname } = useLocation();
const [open, setOpen] = useState(false);
useEffect(() => setOpen(false), [pathname]);
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
<Button>Open navigation</Button>
</SheetTrigger>
<SheetContainer
side="left"
aria-describedby={undefined}
style={{ minWidth: 0 }}
>
<SheetTitle className="sr-only">Navigation</SheetTitle>
<div style={{ display: "flex", height: "100%" }}>
<NavRail aria-label="Main">…</NavRail>
<NavPanel aria-label={`Project: ${project.name}`} header={<NavSwitcher … />}>
…
</NavPanel>
</div>
</SheetContainer>
</Sheet>;Best Practices
Use Nav for Pages, Not Actions
Every row takes the reader somewhere. Put actions elsewhere: Log Out in a Dropdown Menu, Create Project in the switcher’s action. A reader who clicks a row expects to go somewhere, not to change something.
Statuses and Counts in the Suffix
Use Badge size="sm". Screen readers skip the prefix, and a badge there pushes the label out of line.
Icons on Every Top-Level Row, or None
Mixed icons make the labels zigzag.
Don’t Restyle Rows
A row with its own colours or sizes reads as an error, or as a different control.
Don’t Add Your Own Arrows
The row adds them itself: › when you set drill, ↗ when you set target="_blank".
Server-Rendered Pages: Start the Current Folder Open
Pass defaultOpen to the folder holding the current page, so it’s open before the page’s scripts load. With JavaScript off, every folder shows open.
Put a Folder’s Own Page Inside It
A folder’s header only opens and closes the folder; it can’t link to a page. If the folder has a page of its own, add it as the first row inside, such as Overview.
Name the Rail and Panel for What They Hold
Screen readers list NavRail and NavPanel as navigation landmarks by their aria-label. Use names that tell them apart, like “Main” and `Project: ${project.name}`.
Slots
| Name | Description |
|---|---|
NavRail | The column of icon links |
NavRailItem | An icon link in the rail, with its label as a tooltip |
NavPanel | The sidebar panel, with a header |
NavSwitcher | Switches between items, in the panel’s header |
NavList | Root of the rows |
NavListGroup | A list of rows, with an optional label |
NavListItem | A row: a link, or a button for a drill row |
NavListSeparator | Divider between kinds of group |
NavListExpandable | A folder that opens and closes |
NavListExpandableTrigger | The folder’s header row |
NavListExpandableContent | The folder’s rows |
NavDrill | Shows one level at a time and slides between them |
NavDrillLevel | One level of a drill-in, with its ‹ row |
Props
NavList, NavListSeparator and NavListExpandableContent take no props of their own.
NavRail
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
aria-label | Names the rail’s landmark | string | ✅ |
NavRailItem
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
icon | The item’s only visible content | ReactNode | ✅ | |
label | The item’s accessible name and its tooltip | string | ✅ | |
href | Where the item goes | string | Without asChild | |
current | Marks the current section | boolean | false | ❌ |
asChild | Renders the item as its child, like a router link | boolean | false | ❌ |
NavPanel
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
aria-label | Names the panel’s landmark | string | ✅ | |
header | Above the rows: a NavSwitcher or a heading | ReactNode | ❌ |
NavSwitcher
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
label | The current item’s name, shown as the panel’s heading | string | ✅ | |
noun | Singular, for the trigger’s name: {label}, switch {noun} | string | ✅ | |
collection | Plural, for the search and empty copy | string | ✅ | |
options | The items to switch between | { value, label, keywords? }[] | ✅ | |
value | The current item’s value | string | ✅ | |
onValueChange | Called with the picked item’s value | (value: string) => void | ✅ | |
onHighlight | Hover or focus on an option, to preload its page | (value: string) => void | ❌ | |
onHighlightEnd | Hover or focus leaves an option, to cancel the preload | () => void | ❌ | |
action | A command at the foot of the list, kept while searching; runs after the list closes | { label: string; onSelect: () => void } | ❌ | |
error | The list failed to load, and offers Retry | boolean | false | ❌ |
retrying | A retry is running, and the Retry row says so | boolean | false | ❌ |
onRetry | Called when Retry is picked | () => void | With error | |
loading | Holds the switcher’s height while the current item loads | boolean | false | ❌ |
With loading, pass no other props. With no options, action or error, it’s a plain heading.
NavListGroup
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
label | Names the group’s list | string | ❌ |
NavListItem
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
label | The row’s text | string | ✅ | |
href | Makes the row a link | string | ❌ | |
target, rel | Passed to the link. target="_blank" adds ↗, “(opens in a new tab)” and rel="noopener noreferrer" | string | ❌ | |
current | Marks the current page | boolean | false | ❌ |
prefix | An icon before the label; top-level rows only | ReactNode | ❌ | |
suffix | A status or count after the label, read with it | ReactNode | ❌ | |
drill | The level this row opens; adds › | string | ❌ | |
asChild | Renders the row as its child, like a router link | boolean | false | ❌ |
NavListExpandable
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
defaultOpen | Uncontrolled: opens the folder on first render | boolean | false | ❌ |
open | Controlled: whether the folder is open | boolean | ❌ | |
onOpenChange | Called with the new state when the header is pressed, or when the current page moves inside | (open: boolean) => void | ❌ | |
value | Inside NavDrill, keeps the folder open or closed when the reader drills away and back; unique within its level | string | ❌ |
NavListExpandableTrigger
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
label | The folder’s name | string | ✅ | |
prefix | An icon before the label; top-level folders only | ReactNode | ❌ | |
suffix | A status or count after the label, read with it | ReactNode | ❌ |
NavDrill
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
value | Controlled: the current level | string | ❌ | |
defaultValue | Uncontrolled: the first level | string | ❌ | |
onValueChange | Called when a drill row or ‹ asks for a level; request says which | (value: string, request: "drill" | "back") => void | ❌ | |
animate | Slides between levels | boolean | true | ❌ |
NavDrillLevel
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
value | The NavDrill value that shows it | string | ✅ | |
parent | The value ‹ returns to; adds the ‹ row | string | ❌ | |
label | Names where you are, on the ‹ row | string | With parent | |
backLabel | The ‹ row’s accessible name; must start with label | string | {label}, back | ❌ |