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.Closeis 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.Closeapplies 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
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
Drawer.Root | open | boolean | — | Controlled open state |
Drawer.Root | defaultOpen | boolean | false | Initial open state |
Drawer.Root | onOpenChange | (open: boolean) => void | — | Called when open state changes |
Drawer.Root | modal | boolean | true | Whether the drawer is modal (traps focus, blocks interaction outside) |
Drawer.Trigger | render | ReactNode | — | Replace the default trigger element |
Drawer.Trigger | sx | StyleXStyles | — | StyleX override |
Drawer.Backdrop | sx | StyleXStyles | — | StyleX override |
Drawer.Popup | side | 'start' | 'end' | 'left' | 'right' | 'top' | 'bottom' | 'end' | Which edge the drawer slides in from |
Drawer.Popup | sx | StyleXStyles | — | StyleX override |
Drawer.Title | sx | StyleXStyles | — | StyleX override |
Drawer.Description | sx | StyleXStyles | — | StyleX override |
Drawer.Close | render | ReactElement | — | Render this element without the corner X styles |
Drawer.Close | sx | StyleXStyles | — | 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.
Escapecloses the drawer (whenmodal).- Clicking the backdrop closes the drawer (when
modal). - Screen readers announce the drawer via
role="dialog",aria-labelledby(Title), andaria-describedby(Description).
Keyboard
| Key | Action |
|---|---|
Escape | Closes the drawer |
Tab | Moves focus forward within the drawer |
Shift + Tab | Moves focus backward within the drawer |