Skip to content

Nav

Nav

A vertical side navigation (<nav> landmark, default name "Navigation") with items, links and collapsible categories.

- **Selection**: value/defaultValue/onValueChange (onValueChange fires only when the value changes). A click that opens a link in another tab or window (or downloads it) selects nothing, unless the item's onClick prevents the default (client-side routing: then nothing opens elsewhere).
- **Callbacks**: onValueChange(value, details) reports the selected item with the click and the category it sits in, and onOpenCategoriesChange(openCategories, details) the toggled category, whether it is open now and the click.
- **Density**: density="small" sets the rows 8px shorter (data-density).
- **Categories**: openCategories/defaultOpenCategories/onOpenCategoriesChange; multiple={false} keeps at most one category open. Without defaultOpenCategories, the categories containing the selected item (value or defaultValue) start open. A closed category that contains the selected item marks its toggle (aria-current="true", data-contains-current, the selected look); pass currentCategory for sub-items your own component renders inside a closed category.
- **Values** are unique: among the items and sub-items, and among the categories (a duplicate warns in development).
- **Structure**: every child of the Nav, and of a category, is a part or your own <li>; a development warning names anything else (a <div>, text, the wrapper of a Tooltip around an item). Nav.SectionHeader is a heading between groups of items (<h3> unless headingLevel, which stands for the as of Fluent's NavSectionHeader), and Nav.Divider a line between groups, hidden from assistive technology (Fluent's NavDivider is a separator).
- **App identity**: Nav.AppItem shows the app's name and logo at the top, as a link with href or a button; it is never selected. Nav.AppItemStatic shows them as plain text.
- **Item actions**: actions on Nav.Item and Nav.SubItem (Fluent's SplitNavItem) puts your own controls beside the item, in a group named by it; each is a Tab stop after the item, and none selects it. They fade in while the row is hovered or has focus, while one is pressed or has its menu open, and are always drawn on touch screens and in forced colours. With actions, a selected item's background and indicator are drawn on its row (.wave-nav-item__list-item).
- **Motion**: a category's list opens and closes its space with a short collapse and fade (motion on Nav.Category), its chevron's turn is animated (expandIconMotion) and item actions fade in. None of these defaults runs under reduced motion, and a WaveProvider with motion="none" turns them off, while a category's own motion or expandIconMotion value still applies. Focus inside a list that closes moves to its category's toggle button.

Sub-components are also exported under flat names (NavCategory, NavItem, NavSubItem, NavSectionHeader, NavDivider, NavAppItem, NavAppItemStatic): React Server Components import those, because dotted access (Nav.Item) needs a client file.

Examples

Default

export const Default: Story = {};

Selected Sub Item

export const SelectedSubItem: Story = {
  args: {
    defaultValue: 'api',
  },
};

Collapsed Current

export const CollapsedCurrent: Story = {
  args: {
    defaultValue: 'api',
    defaultOpenCategories: [],
  },
};
export const WithLinks: Story = {
  args: {
    children: (
      <>
        <Nav.Item value="home" href="#home">
          Home
        </Nav.Item>
        <Nav.Item value="reports" href="#reports">
          Reports
        </Nav.Item>
        <Nav.Category value="help" label="Help">
          <Nav.SubItem value="faq" href="#faq">
            FAQ
          </Nav.SubItem>
          <Nav.SubItem value="contact" href="#contact">
            Contact
          </Nav.SubItem>
        </Nav.Category>
      </>
    ),
  },
};

Disabled

export const Disabled: Story = {
  args: {
    children: (
      <>
        <Nav.Item value="home">Home</Nav.Item>
        <Nav.Item value="billing" disabled>
          Billing
        </Nav.Item>
        <Nav.Item value="admin" href="#admin" disabled>
          Admin
        </Nav.Item>
      </>
    ),
  },
};

Controlled

Selected: home

export const Controlled: Story = {
  render: function ControlledNav({ defaultValue, onValueChange, ...args }) {
    const [value, setValue] = React.useState(defaultValue ?? 'home');
    const handleValueChange = (next: string) => {
      setValue(next);
      onValueChange?.(next);
    };
    return (
      <div style={{ display: 'flex', gap: 16 }}>
        <Nav value={value} onValueChange={handleValueChange} {...args}>
          <Nav.Item value="home">Home</Nav.Item>
          <Nav.Item value="inbox">Inbox</Nav.Item>
          <Nav.Item value="calendar">Calendar</Nav.Item>
          <Nav.Category value="more" label="More">
            <Nav.SubItem value="tasks">Tasks</Nav.SubItem>
            <Nav.SubItem value="notes">Notes</Nav.SubItem>
          </Nav.Category>
        </Nav>
        <div style={{ padding: 16 }}>
          <p>
            Selected: <strong>{value}</strong>
          </p>
        </div>
      </div>
    );
  },
};

Sections

export const Sections: Story = {
  args: {
    defaultValue: 'dashboard',
    style: { minHeight: 400 },
    children: (
      <>
        <Nav.AppItem href="#start" icon={<AppLogo />}>
          Contoso HR
        </Nav.AppItem>
        <Nav.Item value="dashboard">Dashboard</Nav.Item>
        <Nav.Item value="announcements">Announcements</Nav.Item>
        <Nav.Item value="spotlight">Employee spotlight</Nav.Item>
        <Nav.SectionHeader>Employee management</Nav.SectionHeader>
        <Nav.Category value="jobs" label="Job postings">
          <Nav.SubItem value="openings">Openings</Nav.SubItem>
          <Nav.SubItem value="submissions">Submissions</Nav.SubItem>
        </Nav.Category>
        <Nav.Item value="interviews">Interviews</Nav.Item>
        <Nav.SectionHeader>Benefits</Nav.SectionHeader>
        <Nav.Item value="health">Health plans</Nav.Item>
        <Nav.Category value="retirement" label="Retirement">
          <Nav.SubItem value="plans">Plan information</Nav.SubItem>
          <Nav.SubItem value="contributions">Contributions</Nav.SubItem>
        </Nav.Category>
        <Nav.Divider />
        <Nav.Item value="reports">Reports</Nav.Item>
        <Nav.Item value="settings">Settings</Nav.Item>
      </>
    ),
  },
};

App Item

export const AppItem: Story = {
  args: {
    defaultValue: 'home',
    children: (
      <>
        <Nav.AppItem href="#start" icon={<Avatar name="Contoso HR" size="medium" />}>
          Contoso HR
        </Nav.AppItem>
        <Nav.Item value="home">Home</Nav.Item>
        <Nav.Item value="people">People</Nav.Item>
        <Nav.Divider />
        <Nav.AppItemStatic icon={<AppLogo />}>Fabrikam Portal</Nav.AppItemStatic>
      </>
    ),
  },
};

Item Actions

export const ItemActions: Story = {
  args: {
    defaultValue: 'reports',
    defaultOpenCategories: ['projects'],
    children: (
      <>
        <Nav.Item value="dashboard" actions={<ItemActionSet name="Dashboard" />}>
          Dashboard
        </Nav.Item>
        <Nav.Item value="reports" actions={<ItemActionSet name="Reports" />}>
          Reports
        </Nav.Item>
        <Nav.Item value="archive" disabled actions={<ItemActionSet name="Archive" />}>
          Archive
        </Nav.Item>
        <Nav.Category value="projects" label="Projects">
          <Nav.SubItem value="alpha" actions={<ItemActionSet name="Alpha" />}>
            Alpha
          </Nav.SubItem>
          <Nav.SubItem value="beta" actions={<ItemActionSet name="Beta" />}>
            Beta
          </Nav.SubItem>
        </Nav.Category>
        <Nav.Item value="settings">Settings</Nav.Item>
      </>
    ),
  },
};

Motion

export const Motion: Story = {
  args: {
    defaultOpenCategories: ['settings'],
  },
  render: ({ children: _children, ...args }) => (
    <div className="flex flex-wrap gap-6">
      {motionCases(slowCollapse).map(({ label, motion }) => (
        // The story renders one Nav per case; every other arg is forwarded.
        <Nav key={label} {...args} aria-label={label}>
          <Nav.Item value="home">Home</Nav.Item>
          <Nav.Category
            value="settings"
            label="Settings"
            motion={motion}
            expandIconMotion={typeof motion === 'string' ? slowTurn : motion}
          >
            <Nav.SubItem value="profile">Profile</Nav.SubItem>
            <Nav.SubItem value="account">Account</Nav.SubItem>
            <Nav.SubItem value="privacy">Privacy</Nav.SubItem>
          </Nav.Category>
          <Nav.Category
            value="docs"
            label="Documentation"
            motion={motion}
            expandIconMotion={typeof motion === 'string' ? slowTurn : motion}
          >
            <Nav.SubItem value="getting-started">Getting Started</Nav.SubItem>
            <Nav.SubItem value="api">API Reference</Nav.SubItem>
          </Nav.Category>
        </Nav>
      ))}
    </div>
  ),
};

Custom Expand Icon

export const CustomExpandIcon: Story = {
  render: function CustomExpandIconNav({
    children: _children,
    defaultOpenCategories,
    onOpenCategoriesChange,
    ...args
  }) {
    const [openCategories, setOpenCategories] = React.useState<string[]>(
      defaultOpenCategories ? [...defaultOpenCategories] : [],
    );
    return (
      // The story owns the controlled pair; every other arg is forwarded.
      <Nav
        {...args}
        openCategories={openCategories}
        onOpenCategoriesChange={(next) => {
          setOpenCategories(next);
          onOpenCategoriesChange?.(next);
        }}
      >
        <Nav.Item value="home">Home</Nav.Item>
        <Nav.Category
          value="settings"
          label="Settings"
          expandIcon={<SignGlyph open={openCategories.includes('settings')} />}
        >
          <Nav.SubItem value="profile">Profile</Nav.SubItem>
          <Nav.SubItem value="account">Account</Nav.SubItem>
        </Nav.Category>
        <Nav.Category value="help" label="Help" expandIcon={false}>
          <Nav.SubItem value="faq">FAQ</Nav.SubItem>
          <Nav.SubItem value="contact">Contact</Nav.SubItem>
        </Nav.Category>
      </Nav>
    );
  },
};

Density

export const Density: Story = {
  args: {
    density: 'small',
  },
};

Single Open Category

export const SingleOpenCategory: Story = {
  args: {
    multiple: false,
    defaultOpenCategories: ['settings'],
  },
};

Props

NameTypeRequiredDefaultDescription
valuestringNo

Controlled value of the selected nav item.

defaultValuestringNo''

Selected nav item value for uncontrolled usage.

onValueChange(value: string, details?: NavSelectDetails) => voidNo

Called with the new value when the selection changes (not when the current item is re-selected), and with details: the event (the click) and the category the item sits in (Fluent's onNavItemSelect(event, { value, categoryValue })). details is optional in the type for code written before it existed; WaveUI always passes it.

openCategoriesreadonly string[]No

Controlled list of open category values.

defaultOpenCategoriesreadonly string[]No

Categories open initially (uncontrolled). Without it, the categories that contain the selected item (value, else defaultValue) start open, so the current page is visible on the first render; an empty list keeps every category closed.

onOpenCategoriesChange(openCategories: string[], details?: NavCategoryToggleDetails) => voidNo

Called with the new list of open category values (a new array) when a category is toggled, and with details: the event (the click), the toggled category and whether it is now open (Fluent's onNavCategoryItemToggle(event, { categoryValue })). details is optional in the type for code written before it existed; WaveUI always passes it.

multiplebooleanNotrue

Keep at most one category open (Fluent's multiple, which is true by default): opening a category closes the one that was open, and a Nav that starts with several open (defaultOpenCategories, or the categories that contain the selected item) keeps the first. A controlled openCategories is yours: it is not trimmed, and the next toggle replaces it (opening a category gives [category], closing an open one removes only it).

density'small' | 'medium'No'medium'

How tightly the items and category buttons are set (Fluent's density): medium rows are 36px high (28px for a sub-item) and small ones 8px shorter, with the same text and indentation. Rendered as data-density.

currentCategorystringNo

The value of the category that contains the current item, for sub-items Nav cannot find by itself (rendered by your own component inside a closed category). Usually not needed: Nav finds sub-items among a category's children (through Fragments and wrapper elements) and remembers the category of the current sub-item once it has been shown. A hint, not state: unlike Fluent's selectedCategoryValue it has no default or change callback.

refReact.Ref<HTMLElement>No

Ref to the <nav> element.

slotProps{ list?: SlotPart<'ul'> }No

Props for the list the Nav draws inside its landmark, merged into its own: your classes after its classes (yours win a conflict), your styles, attributes and handlers added, your ref beside its ref. Every attribute it sets is locked and keeps the Nav's value. A part takes no children (they are the Nav's). No handler of the Nav sits on the list: the events of the items reach yours after their own handling. The <nav> takes the Nav's own props. Fluent UI has no such part: its Nav holds the items itself.

Any other prop is passed to the element it renders (HTMLElement).

Parts

  • list
  • Nav.Category
  • Nav.Item
  • Nav.SubItem
  • Nav.SectionHeader
  • Nav.Divider
  • Nav.AppItem
  • Nav.AppItemStatic

Stable class names

PartClass
rootwave-nav
listwave-nav__list