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
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
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
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
The page content sits beside the navigation pane.
The page content sits beside the navigation pane.
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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
type | 'overlay' | 'inline' | No | 'overlay' | How the drawer sits on the page (Fluent's Changing |
open | boolean | No | Controlled open state. | |
defaultOpen | boolean | No | false | 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) => void | No | Called with the new open state when it changes, with | |
onItemSelect | (value: string, details?: NavSelectDetails) => void | No | 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 | |
density | 'small' | 'medium' | No | 'medium' | How tightly the items and category buttons are set (Fluent's |
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. |
size | 'small' | 'medium' | 'large' | 'full' | No | 'small' | The panel's width at a side (its height at the bottom), on Drawer's scale: |
separator | boolean | No | true | Inline drawers: draws a line on the panel's inner edge ( |
modalType | 'modal' | 'non-modal' | No | 'modal' | Overlay drawers: |
unmountOnClose | boolean | No | true | Removes the panel when the drawer closes, once its exit motion has ended. |
mountNode | HTMLElement | null | No | the provider's `portalContainer`, else `document.body` | The element an overlay NavDrawer's panel and backdrop render into, in place of the |
finalFocusRef | React.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. | |
backdrop | Slot<'div'> | (SlotObject<'div'> & { appearance?: BackdropAppearance }) | No | The backdrop of a modal overlay (Drawer's | |
motion | MotionSlot | null | No | the 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 |
backdropMotion | MotionSlot | null | No | the 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 |
aria-label | string | No | '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 |
children | React.ReactNode | No |
| |
ref | React.Ref<HTMLDivElement> | No | Ref to the panel: the | |
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 | |
value | string | No | Controlled value of the selected nav item. | |
defaultValue | string | No | '' | Selected nav item value for uncontrolled usage. |
multiple | boolean | No | true | Keep at most one category open (Fluent's |
onValueChange | (value: string, details?: NavSelectDetails) => void | No | Called with the new value when the selection changes (not when the current item is re-selected), and with | |
openCategories | readonly string[] | No | Controlled list of open category values. | |
defaultOpenCategories | readonly string[] | No | Categories open initially (uncontrolled). Without it, the categories that contain the selected item ( | |
onOpenCategoriesChange | (openCategories: string[], details?: NavCategoryToggleDetails) => void | No | Called with the new list of open category values (a new array) when a category is toggled, and with | |
currentCategory | string | No | The |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
navNavDrawer.HeaderNavDrawer.BodyNavDrawer.Footer
Stable class names
| Part | Class |
|---|---|
root | wave-nav-drawer |
backdrop | wave-nav-drawer__backdrop |
collapse | wave-nav-drawer__collapse |
nav | wave-nav-drawer__nav |