NavItem
A navigation row with an icon, label, and active state, plus sub-items and a collapsed-rail mode for building a sidebar
pnpm add @wandercom/design-system-web
NavItem renders an <a> by default. Pass asChild to merge its props onto a
framework's own link component instead (Next.js shown here), and pass active
yourself — NavItem never reads the route:
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { IconUsers } from '@wandercom/design-system-icons/users';
import { NavItem } from '@wandercom/design-system-web/ui/nav-item';
export function Example() {
const pathname = usePathname();
return (
<NavItem active={pathname === '/guests'} asChild icon={<IconUsers />}>
<Link href="/guests">Guests</Link>
</NavItem>
);
}Rows are 34px tall with no gap between them and an 8px inset: an 18px icon,
then a 14px/450 label at 34px in text-secondary. Hover and the current page
share the surface-quaternary fill; the current page's label turns
text-primary.
Toggle "Collapse" below to see the rows collapse to the icon rail. Finances and Growth are folders:
import { IconChat } from '@wandercom/design-system-icons/chat';
import { IconHome } from '@wandercom/design-system-icons/home';
import {
NavItem,
NavSectionHeader,
} from '@wandercom/design-system-web/ui/nav-item';
export function Example() {
return (
<nav className="flex w-64 flex-col">
<NavItem active icon={<IconHome />} href="/">
Home
</NavItem>
<NavItem
active
icon={<IconChat />}
href="/guests"
subItems={[{ title: 'Messages', href: '/guests/messages' }]}
>
Guests
</NavItem>
<NavSectionHeader>Channels</NavSectionHeader>
<NavItem href="/website">Website</NavItem>
</nav>
);
}Pass subItems — an array of { title, href, active?, onClick? } — to pair a
row with sub-items sharing its styling. NavItem renders them for you, so you
never compose the rows yourself, in an inline panel below the row. Sub-items
have no icon: their label is indented to 34px, in line with their parent's
label. On the rail, sub-items are hidden:
<NavItem
active={isGuestsSectionActive}
asChild
icon={<IconUsers />}
rail={isSideNavCollapsed}
subItems={[
{ title: 'Messages', href: '/guests/messages', active: pathname === '/guests/messages' },
{ title: 'Reviews', href: '/guests/reviews', active: pathname === '/guests/reviews' },
]}
>
<Link href="/guests">Guests</Link>
</NavItem>The row (and, outside rail mode, the panel) opens whenever active is true
or any sub-item's active is — NavItem never tracks this itself.
Leave out href (and asChild) to turn a row with subItems into a folder:
a group of pages with no page of its own, such as "Finances". The row renders
a <button> with a chevron right after its label. Clicking it, or pressing
Enter or Space, opens or closes the panel without
navigating. The button carries aria-expanded and an aria-controls that
points at the sub-item list.
<NavItem
icon={<IconDollar />}
rail={isSideNavCollapsed}
subItems={[
{ title: 'Payouts', href: '/finance/payouts', active: pathname === '/finance/payouts', onClick: navigate },
{ title: 'Charges', href: '/finance/charges', active: pathname === '/finance/charges', onClick: navigate },
{ title: 'Discounts', href: '/finance/discounts', active: pathname === '/finance/discounts', onClick: navigate },
]}
>
Finances
</NavItem>- Open state. Uncontrolled by default. It starts open when one of the
sub-items is
active(override withdefaultOpen). PassopenandonOpenChangeto control it, for example to remember it across reloads. - Opens by itself, never closes by itself. When a sub-item becomes
active(the user navigated into the folder), the folder opens andonOpenChange(true)fires. Moving between pages never closes it, and the user can close it while one of its pages is current. - Active state. The folder row only highlights on hover (or with an
explicit
active); its sub-items never highlight it, open or closed. - Clicks.
onClickruns before the toggle. Callevent.preventDefault()in it to stop the toggle. - Chevron. 16px, tertiary, pointing down when open and right when closed, with no transition.
- Rail. The folder becomes an icon-only link to its first sub-item, with
no popover. A click calls
onClick, then that sub-item'sonClick(for client-side routing), unlessonClickcallsevent.preventDefault().
Use NavSectionHeader to label a group of items, such as a "Channels"
section in a sidebar: 12px/450 tertiary text with an 8px inset and 6px
below it (21px tall). Every header after the first starts its section 20px
below the previous row:
<NavSectionHeader>Channels</NavSectionHeader>
<NavItem icon={<IconGlobe />} href="/website">Website</NavItem>
<NavItem icon={<IconBuilding />} href="/marketplace">Marketplace</NavItem>For a sidebar that's toggled down to icons only, pass rail. The row
becomes a 34×34 icon-only button, with its icon in the same place as when
expanded. Its label is
visually hidden but still announced, and repeated in the button's title
(a native tooltip) and aria-label when it's a string. There is no hover
popover, so a row whose sub-item is the current page carries
aria-current="true". The row keeps the same elements in both states, except that a
folder swaps its button for a link to its first sub-item. Pass the same
rail to NavSectionHeader, which hides its label and draws a 34px
divider line at its top instead, without changing its height:
<NavItem active={pathname === '/'} asChild icon={<IconHome />} rail={isSideNavCollapsed}>
<Link href="/">Home</Link>
</NavItem>icon?:
active?:
subItems?:
open?:
defaultOpen?:
onOpenChange?:
rail?:
subItem?:
asChild?:
className?:
className?:
children?:
rail?:
Deprecated: nothing renders a rail flyout any more, since a rail folder links to its first sub-item. Kept for compatibility.