Organisms · Nav rail
Nav rail
A narrow bar, 64px wide, down the far left of an app. It holds the few sections of the whole app, each an icon over a short label. Picking one usually swaps the Sidebar beside it for that section’s pages.
- Best for
- A narrow app-wide bar of 4–8 sections that each swap a sidebar.
- Not for
- Pages inside one section: use Sidebar.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Requires
- The root TooltipProvider (AppShell and DemoLayout mount it).
Examples
Beside a Sidebar: each section in the rail swaps the column next to it
Code
tsx
type SectionId = 'inbox' | 'work' | 'agents' | 'chat'const SECTIONS: { id: SectionId; label: string; icon: ReactNode }[] = [ { id: 'inbox', label: 'Inbox', icon: <Inbox /> }, { id: 'work', label: 'Work', icon: <Briefcase /> }, { id: 'agents', label: 'Agents', icon: <Bot /> }, { id: 'chat', label: 'Chat', icon: <MessageSquare /> },]const PAGES: Record<SectionId, SidebarGroup[]> = { inbox: [ { title: 'Inbox', collapsible: false, items: [ { label: 'Mentions', href: '#mentions', current: true, count: 2 }, { label: 'Assigned to me', href: '#assigned' }, { label: 'Archive', href: '#archive' }, ], }, ], work: [ { title: 'Views', collapsible: false, items: [ { label: 'My issues', href: '#my-issues', icon: <LayoutList />, current: true }, { label: 'Board', href: '#board', icon: <LayoutList /> }, ], }, { title: 'Projects', items: [ { label: 'Spring restock', href: '#spring-restock', icon: <Folder /> }, { label: 'Warehouse move', href: '#warehouse-move', icon: <Folder /> }, ], }, ], agents: [ { title: 'Agents', collapsible: false, items: [ { label: 'Runs', href: '#runs', icon: <Sparkles />, current: true }, { label: 'Skills', href: '#skills', icon: <Sparkles /> }, ], }, ], chat: [ { title: 'Chats', collapsible: false, items: [ { label: 'Today', href: '#today', current: true }, { label: 'Earlier', href: '#earlier' }, ], }, ],}const FOOTER: NavRailItem[] = [ { id: 'settings', label: 'Settings', icon: <Settings />, href: '#settings' }, { id: 'help', label: 'Help', icon: <CircleHelp />, href: '#help' },]function ShellExample() { const [open, setOpen] = useState<SectionId>('work') const items: NavRailItem[] = SECTIONS.map(section => ({ ...section, current: section.id === open, onSelect: () => setOpen(section.id), })) const title = SECTIONS.find(section => section.id === open)!.label return ( <div className="flex h-96 w-full"> <NavRail label="App sections" items={items} footerItems={FOOTER} className="h-full border-r border-[var(--color-border-hairline)]" /> <div className="min-w-0 flex-1 max-w-64 pl-4 pt-2"> <Sidebar label={`${title} pages`} groups={PAGES[open]} className="border-e-0" /> </div> </div> )}<ShellExample />Badges: a count, a count past 99, a count on the current item and a dot
Code
tsx
const BADGES: NavRailItem[] = [ { id: 'inbox', label: 'Inbox', icon: <Inbox />, href: '#inbox', count: 3 }, { id: 'work', label: 'Work', icon: <Briefcase />, href: '#work', current: true, count: 12 }, { id: 'agents', label: 'Agents', icon: <Bot />, href: '#agents', count: 128 }, { id: 'chat', label: 'Chat', icon: <MessageSquare />, href: '#chat', dot: true },]<NavRail label="Sections with badges" items={BADGES} />Anatomy
| Part | What it is |
|---|---|
| nav | The navigation region, 64px wide. Screen readers call it by the label prop. |
| Header | Optional. Sits above the items: a product mark, a workspace avatar. |
| Item | A link when it has href, a button when it has onSelect. An icon over a label in sentence case, 12px in the body font, the same size on every item; a label of up to eight letters (Settings) fits whole; a longer one ends in an ellipsis, and a tooltip on hover and on focus shows it whole. The current section gets the neutral selected surface, semibold text and a 2px signal-coloured bar on its inline-start edge, plus aria-current="page", which tells a screen reader this is where you are. Hover keeps the faint signal wash, so a hovered item and the current one never look alike. |
| Badge | Optional. A count on the corner of the icon, capped at 99+. A screen reader hears the item as "Work, 3", with the real number even past 99. A count of 0 shows nothing. |
| Dot | Optional. A small square in the signal colour when something is new but there is no number. Read as "Inbox, new". |
| Footer items | Optional. A second list pinned to the bottom of the rail when the rail has a height: settings, help. |
Props
- labelstring
- Required. The name screen readers give the navigation region.
- itemsNavRailItem[]
- Required. Each item has id (the key), label, icon, and either href (a link) or onSelect (a button), never both. Optionally current, count (a corner badge, capped at 99+, read as "<label>, <count>") and dot (a small signal square when there is no number, read as "<label>, new").
- footerItemsNavRailItem[]
- Pinned to the bottom of the rail when it has a height (h-full in a row layout): settings, help. Same shape as items.
- headerReactNode
- Sits above the items: a product mark, a workspace avatar.
- renderLink(props: LinkRenderProps) => ReactNodeDefault a plain anchor
- Pass your router's link component here. Map href to its own prop, and pass className, aria-current and onClick through. Return one element, or the item loses its tooltip.
- classNamestring
- Added to the root classes. Where two Tailwind utility classes clash, the later one wins.
- refRef<HTMLElement>
- The nav element.
Keyboard
| Keys | Result |
|---|---|
| Tab | Moves through each item, top to bottom, then the footer items. Focus shows the label in a tooltip. |
| Enter | Follows a link item, or picks a button item. |
| Space | Picks a button item. |
Do and don't
Do
- Keep it to four to eight sections, each with a label of one short word, eight letters at most.
- Mark the open section current, and keep the Sidebar beside it in step.
- Put settings and help in footerItems, so the main sections stay at the top.
Don't
- Don't put pages of one section here. They belong in the Sidebar.
- Don't show a count of zero, or a dot and a count together. Leave the one you don't need off.
- Don't rely on icons alone. Every item keeps its label.