Skip to content

Drawer

Drawer

A side or bottom panel (Fluent UI v2 style): by default an overlay, modal unless it is non-modal, rendered in a portal (inheriting the WaveProvider theme) while open; with type="inline" a panel in the page layout, rendered in place. With unmountOnClose={false} either kind stays mounted while closed, hidden and inert.

- **Opening**: controlled (open), or uncontrolled with a Drawer.Trigger placed directly inside the Drawer or in a Fragment there (it renders in place, outside the panel); the trigger opens and closes it.
- **Modal**: focus moves into the panel and Tab stays inside it (toasts included), the rest of the page is inert (instead of aria-modal), and the page does not scroll. modalType="alert" renders role="alertdialog", and a backdrop press does not close it.
- **Non-modal**: modalType="non-modal" leaves the page usable (no backdrop, no focus trap, nothing inert, the page scrolls). Focus moves in on open; Tab and Shift+Tab leave the panel in the page's order right after the element that opened it; Escape closes it only while focus is inside it; presses on the page never close it; focus returns to the opener only from inside. Reserve the panel's room in the page layout while it is open, so it hides no page control.
- **Inline**: type="inline" renders the panel where the Drawer is, after its direct triggers, as an <aside> (a complementary landmark named by its title), also in the server HTML. It is page content: no portal, backdrop, focus trap, inert page or scroll lock, and toasts keep their corner next to it. Its trigger toggles it (with aria-expanded and aria-controls, no aria-haspopup); opening it moves no focus; Escape and presses outside never close it; closing it returns focus only when focus was inside. position picks its inner edge and size its width (its height at the bottom); separator draws the inner edge. Place it in your layout, for example a flex row of the panel and the page content. Changing type remounts the panel and its content.
- **Closing**: Escape (only the topmost layer: a popup opened inside closes first), a click on the backdrop (a drag that starts inside does not close it), the Close button and Drawer.Close (an inline drawer: the trigger, the Close button and Drawer.Close). onOpenChange gets the reason as its second argument (details.reason), so a controlled drawer can refuse some of them. A backdrop press blurs the focused field before the drawer closes, so a typed value is committed as with the Close button; when a controlled drawer refuses the press, the field gets focus back. Focus returns to the first of these that can take focus: finalFocusRef, the element that had focus when the drawer opened, the trigger, an element next to where that opener was.
- **Size and position**: position is end (default) or start, which follow the text direction, left or right, or bottom (along the bottom edge, the window wide). size sets the width at a side and the height at the bottom: small (default, 320px), medium (592px), large (940px) or full; the panel never grows past the window (an inline one past its container). A width class in className (a height class for bottom) replaces the size. An overlay panel pads the safe-area insets of the screen edges it touches (the iOS home indicator, once the page sets viewport-fit=cover). Both render as data-position and data-size, next to data-type.
- **Layout**: the title prop and the built-in Close button make the header row; a Drawer.Header replaces it, with a Drawer.HeaderNavigation row (a Back button, commands) and a Drawer.HeaderTitle (the heading, an action area and the Close button). The rest of the content scrolls in the body (Drawer.Body gives it your props); a Drawer.Footer is an action row below the body that never scrolls. Make the parts direct children of the Drawer (a Fragment there is fine). The header draws a line under itself once the body is scrolled, the footer one above itself while content continues below: the body, the header and the footer render the body's scroll state as data-scroll-state (none, top, middle, bottom).
- **Backdrop, Close button and title actions**: the backdrop is the panel's sibling and a slot (backdrop: null removes it, appearance picks dimmed or transparent); a modal opened over another modal dims the page once. closeButton sets the content of every built-in Close button, or hides them (null); a button passed there is merged into it. titleAction places header buttons between the title heading and the Close button.
- **Kept mounted**: unmountOnClose={false} keeps the panel and its content mounted while the drawer is closed, so a form keeps what was typed and the components inside keep their state; each open of an overlay focuses the first focusable element again (an autoFocus inside never applies), and a kept overlay opened while another overlay is open stacks above it. A kept inline drawer is in the server HTML, hidden.
- **Motion**: an overlay panel slides in from its edge and fades in, and slides back and fades out, over 250 ms (small), 300 ms (medium), 400 ms (large) or 500 ms (full), and its backdrop fades with it; an overlay 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, its panel held at its size and fading, so it reads as sliding out from its edge; one open by default does not animate in, and one at full has no motion (a percentage width in className resizes oddly during the motion: give it a length, or pass motion={null}). Under reduced motion every drawer appears and disappears at once. motion (the panel, or an inline drawer's space) and backdropMotion (the backdrop) turn each off (null) or replace it, and WaveProvider motion="none" turns both defaults off. className is a plain class list: data-[presence=…]: classes there apply next to the default motion.
- **Presence**: the panel and the backdrop mount through the presence core and render data-presence (entering and exiting while the drawer's motion runs, entered while open, exited while kept closed). An inline drawer's <aside> is the only child of an element of its own (wave-drawer__collapse), which renders the same phases, carries the inline motion and has no box while open, so the <aside> lays out in your page as without it. The backdrop and the panel (an inline drawer's <aside> and the element around it) are inert while exiting and hidden and inert while kept closed. A closed drawer waits for its motion (the panel's, an inline one's on the element around it) before it unmounts or hides, while focus, the trap, the isolation and the scroll lock follow the open state at once: an exiting overlay lets clicks through to the page (an inert element takes no pointer events). Opened again during its exit, the same panel enters again.

The sub-components are also exported under flat names (DrawerTrigger, DrawerClose, DrawerTitle, DrawerHeader, DrawerHeaderTitle, DrawerHeaderNavigation, DrawerBody, DrawerFooter) for React Server Components, which cannot use the dotted form; dotted access (Drawer.Trigger) needs a client file.

Examples

Default

export const Default: Story = {
  render: renderWithTrigger,
};

Start Position

export const StartPosition: Story = {
  args: { position: 'start', title: 'Navigation' },
  render: renderWithTrigger,
};

Sizes

export const Sizes: Story = {
  render: function SizesDrawers({ children, size: _size, title: _title, ...args }) {
    return (
      <div className="flex flex-wrap gap-2">
        {sizes.map((size) => (
          <Drawer key={size} {...args} size={size} title={`A ${size} drawer`}>
            <Drawer.Trigger>
              <Button>{`Open ${size}`}</Button>
            </Drawer.Trigger>
            <p>{children}</p>
          </Drawer>
        ))}
      </div>
    );
  },
};

Bottom Position

export const BottomPosition: Story = {
  args: { position: 'bottom', size: 'medium', title: 'Details' },
  render: renderWithTrigger,
};

This example opens a dialog or panel. Use the button to show it.

export const HeaderAndFooter: Story = {
  args: { defaultOpen: true },
  parameters: openStoryParameters,
  render: function HeaderAndFooterDrawer({ children, title: _title, ...args }) {
    return (
      <Drawer {...args}>
        <Drawer.Trigger>
          <Button appearance="primary">Open drawer</Button>
        </Drawer.Trigger>
        <Drawer.Header>
          <Drawer.HeaderTitle
            action={
              <Button appearance="subtle" size="small" icon={<ExpandIcon />} aria-label="Expand" />
            }
          >
            Filters
          </Drawer.HeaderTitle>
        </Drawer.Header>
        <p>{children}</p>
        <Drawer.Footer>
          <Drawer.Close>
            <Button appearance="primary">Apply</Button>
          </Drawer.Close>
          <Button>Reset</Button>
        </Drawer.Footer>
      </Drawer>
    );
  },
};

Long Content

export const LongContent: Story = {
  args: { title: 'All filters' },
  render: function LongContentDrawer({ children: _children, ...args }) {
    return (
      <Drawer {...args}>
        <Drawer.Trigger>
          <Button appearance="primary">Open all filters</Button>
        </Drawer.Trigger>
        <div className="flex flex-col gap-3">
          {longFields.map((field) => (
            <Field key={field} label={field}>
              <Input />
            </Field>
          ))}
        </div>
        <Drawer.Footer>
          <Drawer.Close>
            <Button appearance="primary">Apply</Button>
          </Drawer.Close>
          <Button>Reset</Button>
        </Drawer.Footer>
      </Drawer>
    );
  },
};

Form In Drawer

Nothing saved yet.

export const FormInDrawer: Story = {
  render: function FormInDrawerDrawer({ children: _children, title: _title, ...args }) {
    const formId = React.useId();
    const [open, setOpen] = React.useState(false);
    const [saved, setSaved] = React.useState('');
    const handleOpenChange: NonNullable<DrawerProps['onOpenChange']> = (next, details) => {
      setOpen(next);
      args.onOpenChange?.(next, details);
    };
    const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
      event.preventDefault();
      const name = new FormData(event.currentTarget).get('displayName');
      setSaved(typeof name === 'string' ? name : '');
      handleOpenChange(false, { reason: 'close', event: event.nativeEvent });
    };
    return (
      <div className="flex flex-col items-start gap-2">
        {/* The story owns the controlled pair; every other arg is forwarded. */}
        <Drawer {...args} open={open} onOpenChange={handleOpenChange}>
          <Drawer.Trigger>
            <Button appearance="primary">Edit profile</Button>
          </Drawer.Trigger>
          <Drawer.Header>
            <Drawer.HeaderTitle>Profile</Drawer.HeaderTitle>
          </Drawer.Header>
          <form
            id={formId}
            aria-label="Profile"
            className="flex flex-col gap-3"
            onSubmit={handleSubmit}
          >
            <Field label="Display name">
              <Input name="displayName" defaultValue={saved} />
            </Field>
            <Field label="Email">
              <Input name="email" type="email" />
            </Field>
          </form>
          <Drawer.Footer>
            <Button appearance="primary" type="submit" form={formId}>
              Save
            </Button>
            <Drawer.Close>
              <Button>Cancel</Button>
            </Drawer.Close>
          </Drawer.Footer>
        </Drawer>
        <p>{saved ? `Saved as ${saved}.` : 'Nothing saved yet.'}</p>
      </div>
    );
  },
};

Multiple Levels

export const MultipleLevels: Story = {
  render: function MultipleLevelsDrawer({ children: _children, title: _title, ...args }) {
    const [level, setLevel] = React.useState<SettingsLevel>('settings');
    const backRef = React.useRef<HTMLButtonElement>(null);
    const itemRefs = React.useRef<Partial<Record<SettingsLevel, HTMLButtonElement | null>>>({});
    // Set by a level change from inside the drawer; the layout effect then moves focus in the same
    // commit, since the element that had it (the item, or Back) is gone.
    const returnToRef = React.useRef<SettingsLevel | null>(null);
    React.useLayoutEffect(() => {
      const returnTo = returnToRef.current;
      if (returnTo === null) return;
      returnToRef.current = null;
      if (level === 'settings') itemRefs.current[returnTo]?.focus();
      else backRef.current?.focus();
    }, [level]);
    const openLevel = (next: SettingsLevel) => {
      returnToRef.current = level === 'settings' ? next : level;
      setLevel(next);
    };
    const handleOpenChange: NonNullable<DrawerProps['onOpenChange']> = (next, details) => {
      if (!next) setLevel('settings');
      args.onOpenChange?.(next, details);
    };
    return (
      <Drawer {...args} onOpenChange={handleOpenChange}>
        <Drawer.Trigger>
          <Button appearance="primary">Open settings</Button>
        </Drawer.Trigger>
        <Drawer.Header>
          {level !== 'settings' && (
            <Drawer.HeaderNavigation aria-label="Settings levels">
              <Button
                ref={backRef}
                appearance="subtle"
                icon={<BackIcon />}
                onClick={() => openLevel('settings')}
              >
                Back
              </Button>
            </Drawer.HeaderNavigation>
          )}
          <Drawer.HeaderTitle>{levelTitles[level]}</Drawer.HeaderTitle>
        </Drawer.Header>
        {level === 'settings' ? (
          <div className="flex flex-col items-start gap-2">
            {(['notifications', 'privacy'] as const).map((item) => (
              <Button
                key={item}
                ref={(node) => {
                  itemRefs.current[item] = node;
                }}
                appearance="subtle"
                onClick={() => openLevel(item)}
              >
                {levelTitles[item]}
              </Button>
            ))}
          </div>
        ) : level === 'notifications' ? (
          <div className="flex flex-col gap-3">
            <Switch label="Email notifications" defaultChecked />
            <Switch label="Push notifications" />
          </div>
        ) : (
          <div className="flex flex-col gap-3">
            <Switch label="Show my status" defaultChecked />
            <Switch label="Share usage data" />
          </div>
        )}
      </Drawer>
    );
  },
};

Scrollable Text Body

export const ScrollableTextBody: Story = {
  args: { title: 'Terms of service' },
  render: function ScrollableTextBodyDrawer({ children: _children, ...args }) {
    return (
      <Drawer {...args}>
        <Drawer.Trigger>
          <Button appearance="primary">Read the terms</Button>
        </Drawer.Trigger>
        <Drawer.Body tabIndex={0} role="region" aria-label="Terms text">
          <div className="flex flex-col gap-3">
            {termsParagraphs.map((paragraph) => (
              <p key={paragraph}>{paragraph}</p>
            ))}
          </div>
        </Drawer.Body>
        <Drawer.Footer>
          <Drawer.Close>
            <Button appearance="primary">Accept</Button>
          </Drawer.Close>
        </Drawer.Footer>
      </Drawer>
    );
  },
};

Trigger With Tooltip

export const TriggerWithTooltip: Story = {
  render: function TriggerWithTooltipDrawer({ children, ...args }) {
    return (
      <Drawer {...args}>
        <Drawer.Trigger>
          {(triggerProps) => (
            <Tooltip content="Narrow the list">
              <Button appearance="primary" {...triggerProps}>
                Open drawer
              </Button>
            </Tooltip>
          )}
        </Drawer.Trigger>
        <p>{children}</p>
      </Drawer>
    );
  },
};

Controlled

export const Controlled: Story = {
  args: { position: 'start', title: 'Start drawer' },
  render: function ControlledDrawer({ children, ...args }) {
    const [open, setOpen] = React.useState(false);
    const handleOpenChange: NonNullable<DrawerProps['onOpenChange']> = (next, details) => {
      setOpen(next);
      args.onOpenChange?.(next, details);
    };
    return (
      <>
        <Button
          appearance="primary"
          onClick={(event) =>
            handleOpenChange(true, { reason: 'trigger', event: event.nativeEvent })
          }
        >
          Open
        </Button>
        {/* The story owns the controlled pair; every other arg is forwarded. */}
        <Drawer {...args} open={open} onOpenChange={handleOpenChange}>
          <p>{children}</p>
          <Drawer.Footer>
            <Button
              appearance="primary"
              onClick={(event) =>
                handleOpenChange(false, { reason: 'close', event: event.nativeEvent })
              }
            >
              Done
            </Button>
          </Drawer.Footer>
        </Drawer>
      </>
    );
  },
};

Non Modal

This example opens a dialog or panel. Use the button to show it.

export const NonModal: Story = {
  args: {
    modalType: 'non-modal',
    title: 'Order 1042',
    children: 'Two items, shipped on Monday to the warehouse in Lyon.',
  },
  render: function NonModalDrawer({ children, ...args }) {
    const [open, setOpen] = React.useState(true);
    const handleOpenChange: NonNullable<DrawerProps['onOpenChange']> = (next, details) => {
      setOpen(next);
      args.onOpenChange?.(next, details);
    };
    return (
      <div className={open ? 'pe-80' : undefined}>
        <div className="flex flex-col gap-3">
          <p>Orders received this week. Open an order&apos;s details while you keep working.</p>
          <div className="flex flex-wrap gap-2">
            {/* The story owns the controlled pair; every other arg is forwarded. */}
            <Drawer {...args} open={open} onOpenChange={handleOpenChange}>
              <Drawer.Trigger>
                <Button appearance="primary">Order details</Button>
              </Drawer.Trigger>
              <p>{children}</p>
              <Drawer.Footer>
                <Button>Print label</Button>
                <Drawer.Close>
                  <Button appearance="primary">Done</Button>
                </Drawer.Close>
              </Drawer.Footer>
            </Drawer>
            <Button>Refresh</Button>
          </div>
          <Field label="Search orders">
            <Input />
          </Field>
        </div>
      </div>
    );
  },
  parameters: openStoryParameters,
};

Alert Drawer

export const AlertDrawer: Story = {
  args: {
    modalType: 'alert',
    title: 'Discard the draft?',
    children: 'The draft and its attachments are deleted. This cannot be undone.',
  },
  render: ({ children, ...args }) => (
    <Drawer {...args}>
      <Drawer.Trigger>
        <Button>Discard draft</Button>
      </Drawer.Trigger>
      <p>{children}</p>
      <Drawer.Footer>
        <Drawer.Close>
          <Button appearance="subtle">Keep editing</Button>
        </Drawer.Close>
        <Drawer.Close>
          <Button appearance="primary">Discard</Button>
        </Drawer.Close>
      </Drawer.Footer>
    </Drawer>
  ),
};

Keep Mounted

export const KeepMounted: Story = {
  args: {
    unmountOnClose: false,
    title: 'Search filters',
    children: 'The filters stay as you left them when the drawer opens again.',
  },
  render: ({ children, ...args }) => (
    <Drawer {...args}>
      <Drawer.Trigger>
        <Button appearance="primary">Open filters</Button>
      </Drawer.Trigger>
      <div className="flex flex-col gap-3">
        <p>{children}</p>
        <Field label="Keyword">
          <Input />
        </Field>
        <Field label="Author">
          <Input />
        </Field>
        <Switch label="Only available items" />
      </div>
      <Drawer.Footer>
        <Drawer.Close>
          <Button appearance="primary">Done</Button>
        </Drawer.Close>
      </Drawer.Footer>
    </Drawer>
  ),
};

Inline

Orders received this week. The details pane stays open while you work.

export const Inline: Story = {
  args: {
    type: 'inline',
    separator: true,
    defaultOpen: true,
    title: 'Order 1042',
    children: 'Two items, shipped on Monday to the warehouse in Lyon.',
  },
  render: function InlineDrawer({ children, ...args }) {
    return (
      <div className="flex h-96 rounded-md border border-wave-border">
        <div className="flex min-w-0 flex-1 flex-col gap-3 p-4">
          <p>Orders received this week. The details pane stays open while you work.</p>
          <Field label="Search orders">
            <Input />
          </Field>
        </div>
        <Drawer {...args}>
          <Drawer.Trigger>
            <Button className="m-4 self-start">Order details</Button>
          </Drawer.Trigger>
          <p>{children}</p>
          <Drawer.Footer>
            <Button>Print label</Button>
          </Drawer.Footer>
        </Drawer>
      </div>
    );
  },
};

Inline Start

Mail

Select a folder to see its messages.

export const InlineStart: Story = {
  args: {
    type: 'inline',
    position: 'start',
    separator: true,
    title: 'Folders',
    children: 'Inbox, Drafts, Sent and Archive.',
  },
  render: function InlineStartDrawer({ children, ...args }) {
    const [open, setOpen] = React.useState(true);
    const toggleRef = React.useRef<HTMLButtonElement>(null);
    const handleOpenChange: NonNullable<DrawerProps['onOpenChange']> = (next, details) => {
      setOpen(next);
      args.onOpenChange?.(next, details);
    };
    const paneId = 'inline-start-folders';
    return (
      <div className="flex h-96 flex-col rounded-md border border-wave-border">
        <div className="flex items-center gap-2 border-b border-wave-border p-2">
          <Button
            ref={toggleRef}
            aria-expanded={open}
            aria-controls={open ? paneId : undefined}
            onClick={() => setOpen((value) => !value)}
          >
            Folders
          </Button>
          <span className="text-wave-body-1 font-semibold">Mail</span>
        </div>
        <div className="flex min-h-0 flex-1">
          {/* The story owns the controlled pair; every other arg is forwarded. */}
          <Drawer
            {...args}
            id={paneId}
            open={open}
            onOpenChange={handleOpenChange}
            finalFocusRef={toggleRef}
          >
            <p>{children}</p>
          </Drawer>
          <div className="min-w-0 flex-1 p-4">
            <p>Select a folder to see its messages.</p>
          </div>
        </div>
      </div>
    );
  },
};

Inline Bottom

The editor area. The problems pane below keeps its height.

export const InlineBottom: Story = {
  args: {
    type: 'inline',
    position: 'bottom',
    separator: true,
    defaultOpen: true,
    title: 'Problems',
    children: 'No problems in the open files.',
  },
  render: function InlineBottomDrawer({ children, ...args }) {
    return (
      <div className="flex h-128 flex-col rounded-md border border-wave-border">
        <div className="min-h-0 flex-1 p-4">
          <p>The editor area. The problems pane below keeps its height.</p>
        </div>
        <Drawer {...args}>
          <Drawer.Trigger>
            <Button className="mx-4 mb-2 self-start">Problems</Button>
          </Drawer.Trigger>
          <p>{children}</p>
        </Drawer>
      </div>
    );
  },
};

Motion

export const Motion: Story = {
  render: function MotionDrawers({ children, title: _title, ...args }) {
    return (
      <div className="flex flex-wrap gap-2">
        {motionCases(panelFade).map(({ label, motion }) => (
          // The story renders one drawer per case; every other arg is forwarded.
          <Drawer
            key={label}
            {...args}
            title={label}
            motion={motion}
            backdropMotion={typeof motion === 'string' ? backdropFade : motion}
          >
            <Drawer.Trigger>
              <Button>{label}</Button>
            </Drawer.Trigger>
            <p>{children}</p>
            <Drawer.Footer>
              <Drawer.Close>
                <Button appearance="primary">Apply</Button>
              </Drawer.Close>
            </Drawer.Footer>
          </Drawer>
        ))}
      </div>
    );
  },
};

Inline Motion

Orders received this week.

Orders received this week.

Orders received this week.

export const InlineMotion: Story = {
  args: {
    type: 'inline',
    separator: true,
    title: 'Order 1042',
    children: 'Two items, shipped on Monday to the warehouse in Lyon.',
  },
  render: function InlineMotionDrawers({ children, title: _title, ...args }) {
    return (
      <div className="flex flex-col gap-3">
        {motionCases(slowCollapse).map(({ label, motion }) => (
          <div key={label} className="flex h-48 rounded-md border border-wave-border">
            <div className="flex min-w-0 flex-1 flex-col gap-2 p-4">
              <p>Orders received this week.</p>
            </div>
            {/* The story renders one drawer per case; every other arg is forwarded. */}
            <Drawer {...args} title={label} motion={motion}>
              <Drawer.Trigger>
                <Button className="m-4 self-start">{label}</Button>
              </Drawer.Trigger>
              <p>{children}</p>
            </Drawer>
          </div>
        ))}
      </div>
    );
  },
};

Responsive Type

Orders received this week.

export const ResponsiveType: Story = {
  args: {
    separator: true,
    title: 'Filters',
    children: 'Narrow the list of orders.',
  },
  render: function ResponsiveTypeDrawer({ children, ...args }) {
    const wide = useMediaQuery('(min-width: 1024px)');
    const [open, setOpen] = React.useState(wide);
    const [wasWide, setWasWide] = React.useState(wide);
    const [keyword, setKeyword] = React.useState('');
    if (wide !== wasWide) {
      setWasWide(wide);
      setOpen(wide);
    }
    const handleOpenChange: NonNullable<DrawerProps['onOpenChange']> = (next, details) => {
      setOpen(next);
      args.onOpenChange?.(next, details);
    };
    return (
      <div className="flex h-96 rounded-md border border-wave-border">
        <div className="flex min-w-0 flex-1 flex-col gap-3 p-4">
          <p>Orders received this week.</p>
        </div>
        {/* The story owns the controlled pair and the type; every other arg is forwarded. */}
        <Drawer
          {...args}
          type={wide ? 'inline' : 'overlay'}
          open={open}
          onOpenChange={handleOpenChange}
        >
          <Drawer.Trigger>
            <Button className="m-4 self-start">Filters</Button>
          </Drawer.Trigger>
          <div className="flex flex-col gap-3">
            <p>{children}</p>
            <Field label="Keyword">
              <Input value={keyword} onValueChange={setKeyword} />
            </Field>
          </div>
        </Drawer>
      </div>
    );
  },
};

Light Dismiss

Page content

export const LightDismiss: Story = {
  args: { modalType: 'non-modal', lightDismiss: true, title: 'Filters' },
  render: (args) => (
    <div className="flex items-center gap-2">
      <Drawer {...args}>
        <Drawer.Trigger>
          <Button appearance="primary">Open filters</Button>
        </Drawer.Trigger>
        <p>Click on the page to close this drawer.</p>
      </Drawer>
      <p>Page content</p>
    </div>
  ),
};

Mount Node

The drawer renders inside this box.
export const MountNode: Story = {
  render: function MountNodeDrawer(args) {
    const [open, setOpen] = React.useState(false);
    const [node, setNode] = React.useState<HTMLElement | null>(null);
    return (
      <div className="flex flex-col gap-3">
        <Button onClick={() => setOpen(true)}>Open drawer</Button>
        <div ref={setNode} className="text-wave-body-1">
          The drawer renders inside this box.
        </div>
        <Drawer
          {...args}
          open={open}
          onOpenChange={(next) => setOpen(next)}
          mountNode={node}
          title="Mounted in a node"
        >
          Content
        </Drawer>
      </div>
    );
  },
};

Props

NameTypeRequiredDefaultDescription
openbooleanNo

Controlled open state of the drawer. An overlay drawer's panel renders only in the browser: open, it is closed in the server HTML and opens once it has hydrated. An inline drawer renders in the server HTML: open, or hidden when kept mounted (unmountOnClose={false}).

defaultOpenbooleanNofalse

Default open state for uncontrolled usage. An overlay drawer open by default is closed in the server HTML and opens once it has hydrated; an inline one is open in the server HTML.

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

Called with the new open state when it changes. details.reason tells how — trigger, close (a .Close part), close-button (the built-in Close button), escape or outside-press (the backdrop) — so a controlled drawer can refuse only some ways of closing (for example keep a form with unsaved changes open on outside-press); details.event is the DOM event behind the request. WaveUI always passes details. An inline drawer asks only with trigger (its Drawer.Trigger toggles it), close and close-button: Escape and presses outside it never close it.

Fires only when the value changes; a controlled drawer stays as it is until the parent updates open.

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: modal by default (focus moves in and stays there, toasts included; the rest of the page is inert and does not scroll; Escape and a backdrop press close it), or modalType="non-modal".
- inline: a panel in the page layout, rendered where the Drawer is (after its direct Drawer.Triggers) as an <aside>, a complementary landmark named by its title. The page stays usable around it: no backdrop, no focus trap, no portal, no scroll lock; Escape and presses outside do not close it. Opening it leaves focus where it is; closing it while focus is inside returns focus to finalFocusRef, else the element that opened it, else the trigger. position and size pick its inner edge and its width (its height at the bottom); where it sits is up to your layout (a flex row of panel and content, for example). modalType and backdrop do not apply to it, and toasts do not move out of its way: it is page content.

Changing type remounts the panel and its content (what was typed in it is lost); focus inside an overlay that becomes inline returns to the trigger, and focus inside an inline panel that becomes an overlay moves into the overlay. Rendered as data-type.

separatorbooleanNofalse

Inline drawers: draws a line on the panel's inner edge, the edge facing the page content (data-separator). An overlay drawer always draws that edge and ignores this prop. In forced colours an inline drawer's inner edge is always drawn. Fluent's separator.

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

Side of the screen the drawer is attached to. start/end follow the text direction; left/right are physical sides; bottom runs along the bottom edge (size sets its height). An inline drawer takes its place from your layout: position picks its inner edge (the one facing the page content: the end edge of a start panel, the top edge of a bottom one) and the axis size sets. Rendered as data-position.

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

The panel's width at a side — small 320px, medium 592px, large 940px, full the viewport's width — or its height at the bottom (the same values; full the viewport's height). It never exceeds the viewport. An inline panel takes the same sizes, where full is its container's width (height), and never grows past its container. A width class in className (a height class for bottom) replaces it. 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). Rendered as data-size. Fluent's size.

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

modal, alert or non-modal, as Dialog's modalType. modal: the page behind is inert and does not scroll; a backdrop press, Escape, the Close button and Drawer.Close close it. alert: role="alertdialog" (a role you pass wins), and a backdrop press does not close it (Escape still does). non-modal: no backdrop, and the page stays usable — no focus trap, nothing inert, the page scrolls; Tab and Shift+Tab leave the drawer in the page's order right after the element that opened it, Escape closes it while focus is inside it, presses on the page never close it, and focus returns to the opener only when it was inside the drawer. A non-modal drawer covers the page under it while Tab still reaches that page: reserve its width (its height at the bottom) in your layout while it is open, or use modal, or, for a panel beside the content, an inline drawer (type="inline") (with size="full" it covers everything, and a development warning says so). Every type moves focus to the first focusable element on open. Rendered as data-modal-type. Ignored by an inline drawer, which is never modal and renders no data-modal-type. Fluent's modalType.

lightDismissbooleanNofalse

Light dismiss of a non-modal drawer, as Dialog's lightDismiss: a press on the page and focus moving out of the drawer close it, with the reasons outside-press and focus-outside in onOpenChange; the element that opened it counts as inside, so its trigger still toggles it. Without it a non-modal drawer closes only on Escape from inside, the Close button and Drawer.Close. Ignored with modal, alert and by an inline drawer. A WaveUI addition.

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

The backdrop of a modal or alert drawer, as Dialog.Content's backdrop: a div behind the panel, aria-hidden. Shorthand content renders inside it; a slot object's className (merged last), style, data attributes, ref and handlers go to it, and its appearance ('dimmed' or 'transparent') overrides the automatic one: while another modal Dialog or Drawer is open below this one the backdrop is transparent, so the page is dimmed once. null renders no backdrop (the page stays inert, and a press outside still closes a modal drawer); a boolean is no slot. Ignored with modalType="non-modal" and by an inline drawer (a development warning says so). Fluent's backdrop.

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

The drawer's motion. 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, 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 <aside> (wave-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 or alert overlay). 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 modalType="non-modal" and by an inline drawer (a development warning says so, except for null, which asks for no motion anyway). Fluent's OverlayDrawer backdropMotion.

closeButtonSlot<'span'>No

Content of the built-in Close button, in the built-in header and in every Drawer.HeaderTitle, as Dialog.Content's closeButton: decorative content inside the button (the dismiss glyph by default), so the button keeps the name closeLabel; a slot object's aria-label, aria-labelledby or title names it instead, and its handlers run before the close (preventDefault() keeps the drawer open). null hides them all (Drawer.Close, and Escape on an overlay, still close); a boolean is no slot; content that renders nothing keeps the default glyph. A <button> or Wave Button passed here is merged into the built-in button, never nested (a development warning says so), and its text label names the button. Fluent's DrawerHeaderTitle action holds Fluent's close button; WaveUI renders its own.

titleActionSlot<'span'>No

Header buttons for the title prop form, between the heading and the built-in Close button in DOM and Tab order. Ignored, with a development warning, next to a Drawer.Header (use the action of Drawer.HeaderTitle). Interactive: name icon-only buttons. Renders nothing when empty. Fluent's DrawerHeaderTitle action, for the title prop form.

titleReact.ReactNodeNo

Title displayed in the built-in header; it names the drawer (aria-labelledby). Without it, render a Drawer.HeaderTitle (in a Drawer.Header) or a Drawer.Title, or pass aria-label/aria-labelledby. A title that renders nothing ('', [], true) counts as none. Ignored, with a development warning, when the children hold a Drawer.Header, which replaces the built-in header. The heading is an <h2>; for another level use Drawer.HeaderTitle with headingLevel. In the server HTML of an inline drawer only title (or aria-label/aria-labelledby) names the panel: a Drawer.HeaderTitle or Drawer.Title names it once the page has hydrated.

closeLabelstringNo'Close'

Accessible name of the built-in Close button (an icon-only button), in the built-in header and in every Drawer.HeaderTitle. Localize it with the page's language. A text label of a button merged into closeButton names it instead.

finalFocusRefReact.RefObject<HTMLElement | null>No

Where focus goes when the drawer closes, if it can take focus. Otherwise focus returns to the element that had focus when the drawer opened, then to the trigger, then to an element next to where that opener was. An inline or non-modal drawer moves focus on close only when focus was inside it.

unmountOnClosebooleanNotrue

Removes the panel and its content when the drawer closes, once the panel's exit motion has ended. false keeps them mounted while closed, hidden and inert (out of the layout, the Tab order and the accessibility tree), so what was typed and the state of the components inside survive closing and opening again; the content then mounts with the Drawer, closed, and an autoFocus inside it never applies (an overlay focuses its first focusable element on each open). An overlay panel still renders only in the browser; a kept inline panel is in the server HTML, hidden. Kept content still belongs to its form: a required empty field in a closed inline drawer inside a page <form> blocks its submission without a visible message. A popup opened inside that is still open when the drawer closes stays open over the page (a development warning says so): close it first. A key on the Drawer resets the kept content. Fluent's unmountOnClose.

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

The element an overlay drawer's panel and backdrop render into, in place of the WaveProvider's portalContainer or document.body (Fluent's mountNode; a nested WaveProvider with its own portalContainer was the only way before). It keeps the theme classes, direction and token overrides of the provider around the Drawer. Ignored by an inline drawer. The panel is position: fixed, so the node needs no positioning of its own unless a transform or filter on it makes it the containing block.

childrenReact.ReactNodeYes

The drawer's content, placed by the Drawer, also from a Fragment ({isMobile && <>…</>}) and when written in a Server Component: Drawer.Trigger children render in place (outside the panel); a Drawer.Header replaces the built-in header (the title and Close button row); a Drawer.Body gives the scrolling body its props; Drawer.Footer renders below the scrolling body, outside it, wherever it is written among the children; everything else renders in the scrolling body. A part nested in another element (a <form>) or rendered by a component of yours renders where it is, in the body (a development warning says so). A Drawer.Trigger nested in another element, or rendered by a component, is panel content, so it is not rendered (or, kept mounted, is hidden) while the drawer is closed (development warnings say so, also when an uncontrolled drawer still has no direct trigger a second after it mounts and therefore cannot open; a controlled drawer whose trigger a component such as a Tooltip wraps warns only once it renders in the panel). Put wrappers inside the trigger instead: see Drawer.Trigger.

refReact.Ref<HTMLElement>No

Ref to the panel: the role="dialog" element of an overlay drawer (alertdialog with modalType="alert"), the <aside> of an inline one. A ref to a div still type-checks.

slotProps{ header?: SlotPart<'div'> }No

Props for the elements the drawer draws around your content, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref attached. Every attribute the drawer sets on a part is locked and keeps the drawer's value; you add the attributes it does not set. 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 Drawer's own props, the scrolling body the props of a Drawer.Body, and the backdrop, the title action and the Close button are the backdrop, titleAction and closeButton slots. Fluent UI's DrawerHeader is a component you write, as Drawer.Header is here.

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

Parts

  • header
  • Drawer.Trigger
  • Drawer.Close
  • Drawer.Title
  • Drawer.Header
  • Drawer.HeaderTitle
  • Drawer.HeaderNavigation
  • Drawer.Body
  • Drawer.Footer

Stable class names

PartClass
rootwave-drawer
backdropwave-drawer__backdrop
collapsewave-drawer__collapse
headerwave-drawer__header
titleActionwave-drawer__title-action
closeButtonwave-drawer__close-button
bodywave-drawer__body