Drawer

An overlay panel that slides in from any edge of the viewport.

Import

import { Drawer } from '@matix/components/drawer';

Usage

Sides

Pass side to Drawer.Popup to change which edge it slides in from. Valid values are start, end (default), left, right, top, and bottom. start and end follow the reading direction, so they flip in right-to-left pages.

Mobile Nav Pattern

Drawer is the canonical mobile nav primitive — hidden on desktop, triggered by a hamburger icon on small viewports. Pair with NavigationMenu or a plain list of links.

import * as stylex from '@stylexjs/stylex';
import { colors } from '@matix/tokens/colors.stylex';
import { spacing } from '@matix/tokens/spacing.stylex';

const styles = stylex.create({
  nav: { display: 'flex', flexDirection: 'column', gap: spacing['2'], marginTop: spacing['6'] },
  link: { color: colors.fgBase, textDecoration: { default: 'none', ':hover': 'underline' } },
});

<Drawer.Root>
  <Drawer.Trigger render={<Button variant="ghost" size="sm" />}>Menu</Drawer.Trigger>
  <Drawer.Portal>
    <Drawer.Backdrop />
    <Drawer.Popup side="left">
      <Drawer.Close />
      <Drawer.Title>Menu</Drawer.Title>
      <nav {...stylex.props(styles.nav)}>
        <a href="#" {...stylex.props(styles.link)}>
          Home
        </a>
        <a href="#" {...stylex.props(styles.link)}>
          Features
        </a>
        <a href="#" {...stylex.props(styles.link)}>
          Pricing
        </a>
      </nav>
    </Drawer.Popup>
  </Drawer.Portal>
</Drawer.Root>;

Close Buttons

Drawer.Close has two forms:

  • Corner X. Without render, Drawer.Close is a small icon button in the top-right corner of the drawer. With no children, it shows an X icon and has the label "Close drawer".
  • Footer button. With render, Drawer.Close applies no styles of its own. The rendered element sets the look and the position.
<Drawer.Close />
<Drawer.Close render={<Button variant="outline" />}>Done</Drawer.Close>

Animation

Each side uses its own slide-in and slide-out keyframes. Animations respect prefers-reduced-motion automatically and can be disabled globally via MatixProvider animate={false}.

Backdrop Blur

colors.overlay sets the backdrop color. To blur the page behind the backdrop, set the --mtx-overlay-backdrop-filter custom property. The Dialog, AlertDialog, and Drawer backdrops read it. The default is none.

:root {
  --mtx-overlay-backdrop-filter: blur(4px);
}

Stacking

The overlays use the zIndex scale from @matix/tokens/z-index.stylex. Backdrops use overlay (1300) and modal popups use modal (1400). Select, Menu, Popover, Combobox, NavigationMenu, and DatePicker popups use popover (1500), and tooltips use tooltip (1600). Thus a popup that opens from inside a modal shows above it.

Server Components

Drawer is a client component. A Server Component cannot read a property of a client component, so Drawer.Root is undefined there. In a Server Component, import the named parts. Each Drawer.<Part> is also exported as Drawer<Part>.

import {
  DrawerRoot,
  DrawerTrigger,
  DrawerPortal,
  DrawerBackdrop,
  DrawerPopup,
  DrawerTitle,
  DrawerDescription,
  DrawerClose,
} from '@matix/components/drawer';

In a client component, both forms work.

API Reference

ComponentPropTypeDefaultDescription
Drawer.Rootopenboolean—Controlled open state
Drawer.RootdefaultOpenbooleanfalseInitial open state
Drawer.RootonOpenChange(open: boolean) => void—Called when open state changes
Drawer.RootmodalbooleantrueWhether the drawer is modal (traps focus, blocks interaction outside)
Drawer.TriggerrenderReactNode—Replace the default trigger element
Drawer.TriggersxStyleXStyles—StyleX override
Drawer.BackdropsxStyleXStyles—StyleX override
Drawer.Popupside'start' | 'end' | 'left' | 'right' | 'top' | 'bottom''end'Which edge the drawer slides in from
Drawer.PopupsxStyleXStyles—StyleX override
Drawer.TitlesxStyleXStyles—StyleX override
Drawer.DescriptionsxStyleXStyles—StyleX override
Drawer.CloserenderReactElement—Render this element without the corner X styles
Drawer.ClosesxStyleXStyles—StyleX override

All other props are forwarded to the underlying Base UI Dialog element.

Accessibility

  • Built on Base UI Dialog — implements WAI-ARIA dialog pattern.
  • Focus is trapped inside the drawer while open and restored on close.
  • Escape closes the drawer (when modal).
  • Clicking the backdrop closes the drawer (when modal).
  • Screen readers announce the drawer via role="dialog", aria-labelledby (Title), and aria-describedby (Description).

Keyboard

KeyAction
EscapeCloses the drawer
TabMoves focus forward within the drawer
Shift + TabMoves focus backward within the drawer