Skip to content

NavDrawer

NavDrawer

A navigation pane in a drawer: Nav's items, categories and selection in a <nav> landmark that sits over the page (type="overlay") or in the page layout (type="inline"). Fluent's NavDrawer.

- **Composition:** NavDrawer.Header (a row: a Hamburger, the app's name), NavDrawer.Body (the scrolling list) and NavDrawer.Footer (a list pinned below it), rendered in the order written. Nav parts (Nav.Item, Nav.Category, Nav.SectionHeader, Nav.Divider, Nav.AppItem, …) go in the Body and the Footer, which render the lists; wrap anything else there in an <li>.
- **Types:** overlay (default) is a panel over the page, in a portal, opened in the browser only; inline is a panel in the page layout, also in the server HTML. Changing type remounts the panel; the selection and the open categories are kept.
- **Opening and closing:** keep it controlled (open, onOpenChange): an uncontrolled drawer that is closed cannot open again. A Hamburger inside it toggles it (reason trigger); Escape and a backdrop press close an overlay (escape, outside-press). Closing an overlay when an item is chosen is yours, in onItemSelect, which also fires when the current page is activated again. A non-modal overlay (modalType="non-modal") covers the page, which keeps its Tab order: keep the page's controls clear of it, or use type="inline".
- **Motion:** an overlay slides in from its edge and fades in, and slides back and fades out, over 250 ms (small, the default), 300 ms (medium), 400 ms (large) or 500 ms (full), with its backdrop fading along; one open by default animates in when it mounts in the browser. An inline drawer opens and closes the space it takes in the layout over the same durations, in an element of its own around the panel (wave-nav-drawer__collapse, which has no box while open); one open by default does not animate in, and one at full has no motion. Under reduced motion every drawer appears and disappears at once. motion and backdropMotion turn each off (null) or replace it, and WaveProvider motion="none" turns both defaults off. While it exits the panel stays on screen, inert, and focus, the trap and the scroll lock are already released.
- **Focus:** pass your page's Hamburger as finalFocusRef, so focus returns to it when a Hamburger inside the drawer closes it. An overlay moves focus in when it opens; an inline drawer does not.
- **Keyboard:** every item is a Tab stop; NavDrawer.Body focusMode="arrow" makes the body one Tab stop with arrow keys, Home and End.
- **Landmark:** one <nav>, named "Navigation" by default (aria-label, aria-labelledby); an overlay is also a dialog with that name. Rename it when the page has another navigation landmark.
- **Selection:** Nav's value/onValueChange (only on a change), openCategories and currentCategory, and onItemSelect on every activation (Fluent's selectedValue and onNavItemSelect).
- **Server Components:** the parts are also exported as NavDrawerHeader, NavDrawerBody and NavDrawerFooter.

Examples

Default

The page content sits beside the navigation pane.

export const Default: Story = {
  render: function DefaultNavDrawer(args) {
    return (
      <Frame>
        <NavDrawer {...args}>
          <NavDrawer.Header>
            <span className="ps-1.5 text-wave-subtitle-2 font-semibold">Contoso HR</span>
          </NavDrawer.Header>
          <NavDrawer.Body>{bodyItems}</NavDrawer.Body>
          {footer}
        </NavDrawer>
        <Content />
      </Frame>
    );
  },
};

Overlay

Contoso HR
export const Overlay: Story = {
  args: { type: 'overlay' },
  render: function OverlayNavDrawer(args) {
    const { open, setOpen, outerRef, drawerProps } = useOverlayDrawer(args, 'overlay-nav');
    return (
      <div className="flex items-center gap-2">
        <Hamburger
          ref={outerRef}
          aria-expanded={open}
          aria-controls={open ? 'overlay-nav' : undefined}
          aria-haspopup="dialog"
          onClick={() => setOpen(!open)}
        />
        <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
        <NavDrawer {...args} {...drawerProps}>
          <NavDrawer.Header>
            <Hamburger />
            <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
          </NavDrawer.Header>
          <NavDrawer.Body>{bodyItems}</NavDrawer.Body>
          {footer}
        </NavDrawer>
      </div>
    );
  },
};

Arrow Keys

The page content sits beside the navigation pane.

export const ArrowKeys: Story = {
  args: { defaultValue: 'reports' },
  render: function ArrowKeysNavDrawer(args) {
    return (
      <Frame>
        <NavDrawer {...args}>
          <NavDrawer.Header>
            <span className="ps-1.5 text-wave-subtitle-2 font-semibold">Contoso HR</span>
          </NavDrawer.Header>
          <NavDrawer.Body focusMode="arrow">
            <Nav.Item value="home" icon={<HomeGlyph />} actions={<ItemActions name="Home" />}>
              Home
            </Nav.Item>
            <Nav.Item
              value="reports"
              icon={<ChartGlyph />}
              actions={<ItemActions name="Reports" />}
            >
              Reports
            </Nav.Item>
            <Nav.Category value="employees" label="Employees" icon={<PeopleGlyph />}>
              <Nav.SubItem value="directory">Directory</Nav.SubItem>
              <Nav.SubItem value="org-chart">Org chart</Nav.SubItem>
            </Nav.Category>
          </NavDrawer.Body>
          {footer}
        </NavDrawer>
        <Content />
      </Frame>
    );
  },
};

End Position

The page content sits beside the navigation pane.

export const EndPosition: Story = {
  args: { position: 'end' },
  render: function EndNavDrawer(args) {
    return (
      <Frame>
        <Content />
        <NavDrawer {...args}>
          <NavDrawer.Body>{bodyItems}</NavDrawer.Body>
          {footer}
        </NavDrawer>
      </Frame>
    );
  },
};

Keep Mounted

Contoso HR

The page content sits beside the navigation pane.

export const KeepMounted: Story = {
  args: { unmountOnClose: false },
  render: function KeepMountedNavDrawer(args) {
    const [open, setOpen] = React.useState(true);
    const outerRef = React.useRef<HTMLButtonElement>(null);
    return (
      <div className="flex h-120 flex-col overflow-hidden rounded-md border border-wave-border bg-wave-background text-wave-foreground">
        <div className="flex items-center gap-2 border-b border-wave-border p-2">
          <Hamburger
            ref={outerRef}
            aria-expanded={open}
            aria-controls="kept-nav"
            onClick={() => setOpen(!open)}
          />
          <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
        </div>
        <div className="flex min-h-0 flex-1">
          <NavDrawer
            {...args}
            id="kept-nav"
            open={open}
            finalFocusRef={outerRef}
            onOpenChange={(next, details) => {
              setOpen(next);
              args.onOpenChange?.(next, details);
            }}
          >
            <NavDrawer.Body>
              <Nav.Item value="home" icon={<HomeGlyph />} actions={<ItemActions name="Home" />}>
                Home
              </Nav.Item>
              <Nav.Item value="reports" icon={<ChartGlyph />}>
                Reports
              </Nav.Item>
            </NavDrawer.Body>
          </NavDrawer>
          <Content />
        </div>
      </div>
    );
  },
};

Non Modal

Contoso HR

The page stays usable while the navigation is open.

export const NonModal: Story = {
  args: { type: 'overlay', modalType: 'non-modal' },
  render: function NonModalNavDrawer(args) {
    const { open, setOpen, outerRef, drawerProps } = useOverlayDrawer(args, 'non-modal-nav');
    return (
      <div className={open ? 'ps-80' : undefined}>
        <div className="flex items-center gap-2">
          <Hamburger
            ref={outerRef}
            aria-expanded={open}
            aria-controls={open ? 'non-modal-nav' : undefined}
            aria-haspopup="dialog"
            onClick={() => setOpen(!open)}
          />
          <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
        </div>
        <p className="mt-4">The page stays usable while the navigation is open.</p>
        <NavDrawer {...args} {...drawerProps}>
          <NavDrawer.Header>
            <Hamburger />
            <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
          </NavDrawer.Header>
          <NavDrawer.Body>{bodyItems}</NavDrawer.Body>
          {footer}
        </NavDrawer>
      </div>
    );
  },
};

Motion

Default motion

The page content sits beside the navigation pane.

No motion

The page content sits beside the navigation pane.

Custom motion

The page content sits beside the navigation pane.

export const Motion: Story = {
  render: function MotionNavDrawers(args) {
    const replacement = args.type === 'overlay' ? panelFade : slowCollapse;
    return (
      <div className="flex flex-col gap-3">
        {motionCases(replacement).map(({ label, motion }, index) => (
          <MotionPane
            key={`${label}-${args.type}`}
            args={args}
            label={label}
            motion={motion}
            id={`motion-nav-${index}`}
          />
        ))}
      </div>
    );
  },
};

App Shell

Home

The content of the page. Choose a page in the navigation, or open the details.

export const AppShell: Story = {
  render: function AppShellStory(args) {
    const narrow = useNarrow();
    const [previousNarrow, setPreviousNarrow] = React.useState(narrow);
    const [navOpen, setNavOpen] = React.useState(!narrow);
    const [detailsOpen, setDetailsOpen] = React.useState(false);
    const [page, setPage] = React.useState(args.defaultValue ?? 'home');
    // The breakpoint decides the open states (adjusted during render, C-HOOKS): a resize never
    // turns an open inline pane into a page-blocking modal.
    if (narrow !== previousNarrow) {
      setPreviousNarrow(narrow);
      setNavOpen(!narrow);
      setDetailsOpen(false);
    }
    const type = narrow ? 'overlay' : 'inline';
    const outerRef = React.useRef<HTMLButtonElement>(null);
    const navId = 'app-shell-nav';
    const detailsId = 'app-shell-details';

    return (
      <div className="flex h-150 flex-col overflow-hidden rounded-md border border-wave-border bg-wave-background text-wave-foreground">
        <Toolbar aria-label="App" className="border-b border-wave-border px-2 py-1">
          <Hamburger
            ref={outerRef}
            aria-expanded={navOpen}
            aria-controls={navOpen ? navId : undefined}
            aria-haspopup={narrow ? 'dialog' : undefined}
            onClick={() => setNavOpen(!navOpen)}
          />
          <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
          <Toolbar.Button
            className="ms-auto"
            aria-expanded={detailsOpen}
            aria-controls={detailsOpen ? detailsId : undefined}
            onClick={() => setDetailsOpen(!detailsOpen)}
          >
            Details
          </Toolbar.Button>
        </Toolbar>
        <div className="flex min-h-0 flex-1">
          <NavDrawer
            {...args}
            id={navId}
            aria-label="Main"
            type={type}
            open={navOpen}
            finalFocusRef={outerRef}
            onOpenChange={(next, details) => {
              setNavOpen(next);
              args.onOpenChange?.(next, details);
            }}
            onValueChange={(value) => {
              setPage(value);
              args.onValueChange?.(value);
            }}
            onItemSelect={(value) => {
              // An overlay closes on every activation, the current page included.
              if (narrow) setNavOpen(false);
              args.onItemSelect?.(value);
            }}
          >
            {narrow && (
              <NavDrawer.Header>
                <Hamburger />
                <span className="text-wave-subtitle-2 font-semibold">Contoso HR</span>
              </NavDrawer.Header>
            )}
            <NavDrawer.Body>{bodyItems}</NavDrawer.Body>
            {footer}
          </NavDrawer>
          <div className="min-w-0 flex-1 overflow-auto p-6">
            <h2 className="text-wave-title-3 font-semibold">{PAGE_TITLES[page] ?? page}</h2>
            <p className="mt-2">
              The content of the page. Choose a page in the navigation, or open the details.
            </p>
          </div>
          <Drawer
            id={detailsId}
            type={type}
            position="end"
            separator
            title="Details"
            open={detailsOpen}
            onOpenChange={setDetailsOpen}
          >
            <p>Owner: People team. Last updated on Monday.</p>
          </Drawer>
        </div>
      </div>
    );
  },
};

Props

NameTypeRequiredDefaultDescription
type'overlay' | 'inline'No'overlay'

How the drawer sits on the page (Fluent's type).
- overlay: a panel over the page, rendered in a portal while open (in the browser only: an open overlay is closed in the server HTML and opens once hydrated). Modal by default: focus moves in and stays there, the rest of the page is inert and does not scroll, and Escape and a backdrop press close it. It is a dialog with the navigation's name.
- inline: a panel in the page layout, rendered where the NavDrawer is (also in the server HTML). The page stays usable around it; Escape and presses outside do nothing; opening it moves no focus, and closing it while focus is inside returns focus to finalFocusRef, else to the element that opened it.

Changing type remounts the panel; the selection and the open categories are kept. Rendered as data-type.

openbooleanNo

Controlled open state.

defaultOpenbooleanNofalse

Open state for uncontrolled usage. Keep the drawer controlled instead: a closed uncontrolled NavDrawer cannot be opened again (a Hamburger inside it is not shown while it is closed).

onOpenChange(open: boolean, details: DrawerOpenChangeDetails) => voidNo

Called with the new open state when it changes, with details.reason: trigger (a Hamburger inside the drawer), escape and outside-press (the backdrop; overlay only), and the event as details.event. WaveUI always passes details. A controlled drawer stays as it is until you update open.

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

Called with an item's value every time an item is activated, also when the current page is activated again (a disabled item, a link opened in another tab or window, and a button item whose onClick calls preventDefault() are not activations). Close an overlay drawer here: onValueChange fires only when the value changes. It gets the same details as onValueChange: the click as event and the category the item sits in. Fluent's onNavItemSelect.

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

How tightly the items and category buttons are set (Fluent's density, which Fluent's NavDrawer takes beside its size): see Nav.density. Rendered as data-density on the <nav>.

position'start' | 'end' | 'left' | 'right' | 'bottom'No'start'

The edge the panel is attached to: an overlay's screen edge; an inline panel's inner edge is the opposite one. start/end follow the text direction; left/right are physical sides; bottom runs along the bottom edge. Unlike Drawer's ('end'), the default is the start edge, where navigation sits (Fluent's). Rendered as data-position.

size'small' | 'medium' | 'large' | 'full'No'small'

The panel's width at a side (its height at the bottom), on Drawer's scale: small 320px, medium 592px, large 940px, full the viewport (inline: the container). A width class in className replaces it (Fluent's navigation pane is 260px wide: the width class of 65 spacing steps). It also times the motion, an overlay's slide and an inline drawer's collapse alike: 250 ms small, 300 ms medium, 400 ms large, 500 ms full (an inline drawer at full has no motion; see motion), so a drawer without size takes 250 ms whatever width a class gives it. Rendered as data-size. Drawer's default too.

separatorbooleanNotrue

Inline drawers: draws a line on the panel's inner edge (data-separator), as Nav does (Drawer's separator defaults to false). An overlay always draws that edge; forced colours always draw it.

modalType'modal' | 'non-modal'No'modal'

Overlay drawers: modal (backdrop, focus trapped, page inert and not scrolling) or non-modal (no backdrop, no trap, nothing inert; Escape closes it while focus is inside, and its Tab place follows the element that opened it). A non-modal overlay covers the page under it while the page keeps its Tab order: keep the page's controls clear of it (reserve its width, or its height at the bottom, in your layout while it is open) or use type="inline"; with size="full" it hides the whole page and warns. Ignored by inline drawers. Rendered as data-modal-type on an overlay's panel. Fluent's modalType (without alert: a navigation pane is never an alert, so an 'alert' is treated as 'modal'). Drawer's default too.

unmountOnClosebooleanNotrue

Removes the panel when the drawer closes, once its exit motion has ended. false keeps it mounted while closed, out of view and inert, so the state of what is inside survives, and a Hamburger outside can point aria-controls at it at all times: always for an inline drawer, and once the page has hydrated for an overlay (whose panel is not in the server HTML). Fluent's unmountOnClose. Drawer's default too.

mountNodeHTMLElement | nullNothe provider's `portalContainer`, else `document.body`

The element an overlay NavDrawer's panel and backdrop render into, in place of the WaveProvider's portalContainer or document.body (Fluent's mountNode). Ignored by an inline NavDrawer. See Drawer's mountNode.

finalFocusRefReact.RefObject<HTMLElement | null>No

Where focus goes when the drawer closes with focus inside it (a modal overlay: whenever it closes). Pass your page's Hamburger, so a Hamburger inside the drawer that closes it hands focus to the one that opens it again.

backdropSlot<'div'> | (SlotObject<'div'> & { appearance?: BackdropAppearance })No

The backdrop of a modal overlay (Drawer's backdrop slot: null renders none, a slot object's appearance picks the fill). Ignored, with a development warning, by a non-modal or inline drawer.

motionMotionSlot | nullNothe slide (overlay) or the collapse (inline) above

The drawer's motion, as Drawer's. By default an overlay panel slides in from beyond its edge and fades in with a decelerating curve, and slides back out and fades out with an accelerating curve; the start and end edges follow the text direction, left and right do not mirror, and a bottom panel rises from below. An inline drawer by default opens the space it takes in your layout from nothing (its width at a side, its height at the bottom) while its panel fades in, held at its size against its inner edge, so it reads as sliding out from that edge, with a decelerating curve; closing runs the same backwards with an accelerating curve. Both take a duration that follows size both ways: 250 ms small (also without size), 300 ms medium, 400 ms large, 500 ms full. An inline drawer at full has no motion, as its size is its container's (a value here does not apply to it either), and an inline drawer whose width (height at the bottom) in className is a percentage resizes oddly during the motion, correctly once open: give it a length, or pass null. Under reduced motion the drawer appears and disappears at once. null turns the motion off (the drawer still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. They go on the overlay panel, or on the element around an inline drawer's panel (wave-nav-drawer__collapse), whose phases the drawer waits for. className is a plain class list on the panel: data-[presence=…] classes there apply next to the default motion, and the drawer still waits for the motion above, so pass a motion of your own here. Fluent's OverlayDrawer and InlineDrawer surfaceMotion.

backdropMotionMotionSlot | nullNothe fade above

The backdrop's motion (a modal overlay), as Drawer's. By default it fades in and out with a linear curve over the panel's duration (250 to 500 ms, by size), so it ends with the panel; under reduced motion it appears and disappears at once. null turns the motion off; a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. The panel's motion decides when the drawer unmounts or hides: a replacement longer than the panel's exit is cut off there. Ignored, with a development warning, by a non-modal or inline drawer. Fluent's OverlayDrawer backdropMotion.

aria-labelstringNo'Navigation'

Name of the navigation landmark (and of an overlay's dialog). Localize it; rename it when the page has another navigation landmark (two with one name are ambiguous). An aria-labelledby replaces the default.

childrenReact.ReactNodeNo

NavDrawer.Header, NavDrawer.Body and NavDrawer.Footer, rendered in the order written.

refReact.Ref<HTMLDivElement>No

Ref to the panel: the role="dialog" element of an overlay drawer, the panel element of an inline one.

slotProps{ nav?: SlotPart<'nav'> }No

Props for the element the drawer draws inside its panel, by part, merged into its own: your classes after its classes (yours win a conflict), your styles, attributes and handlers added, your ref beside its ref, and your ids added after its own to aria-labelledby and aria-describedby. Every other attribute it sets is locked and keeps the drawer's value. A part takes no children. No part carries a handler of the drawer: yours run as those of the content do, before the drawer's own handling of the event, which preventDefault() in yours skips as it does in the content (an Escape you prevent keeps an overlay open). The panel takes the NavDrawer's own props and the backdrop is the backdrop slot. Fluent UI has no such part: its NavDrawer is the landmark itself.

valuestringNo

Controlled value of the selected nav item.

defaultValuestringNo''

Selected nav item value for uncontrolled usage.

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).

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.

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.

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

Parts

  • nav
  • NavDrawer.Header
  • NavDrawer.Body
  • NavDrawer.Footer

Stable class names

PartClass
rootwave-nav-drawer
backdropwave-nav-drawer__backdrop
collapsewave-nav-drawer__collapse
navwave-nav-drawer__nav