Todae

Todae

Drawer

A modal native <dialog> pinned to the start or end edge, full height. Drawer.Root takes the same props as Dialog.Root, except role, plus side, and the inside is built from Drawer's own parts: Drawer.Header, Drawer.Title, Drawer.Description, Drawer.Body, Drawer.Footer and Drawer.Close.

On this page

Drawer.Header lays its children out in one row. A Drawer.Close placed directly in the header sits at the end with anything after it, and what comes before it, such as the title, stays at the start. Drawer.Body takes the height the header and footer leave and scrolls on its own, so the header stays at the top and the footer at the bottom.

side is end by default. Start and end follow text direction, so in right-to-left text end is the left edge.

import { Button, Drawer, type DrawerSide } from '@tounsoo/todae';
import { useState } from 'react';

function FiltersDrawer({ side }: { side: DrawerSide }) {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button.Root variant="secondary" onClick={() => setOpen(true)}>
        {side === 'start' ? 'Open at start' : 'Open at end'}
      </Button.Root>
      <Drawer.Root open={open} onOpenChange={setOpen} side={side}>
        <Drawer.Header>
          <Drawer.Title>Filters</Drawer.Title>
          <Drawer.Close />
        </Drawer.Header>
        <Drawer.Body>The body fills the height the header and footer leave, and scrolls on its own.</Drawer.Body>
        <Drawer.Footer>
          <Button.Root variant="secondary" onClick={() => setOpen(false)}>
            Reset
          </Button.Root>
          <Button.Root onClick={() => setOpen(false)}>Apply</Button.Root>
        </Drawer.Footer>
      </Drawer.Root>
    </>
  );
}

export default function DrawerSides() {
  return (
    <>
      <FiltersDrawer side="end" />
      <FiltersDrawer side="start" />
    </>
  );
}

Filters

The body fills the height the header and footer leave, and scrolls on its own.

Filters

The body fills the height the header and footer leave, and scrolls on its own.

Accessible composition

Todae handles: Drawer.Root runs the same modal code as Dialog.Root, so everything on Dialog holds: a native modal <dialog> that makes the page behind it inert, aria-labelledby and aria-describedby from Drawer.Title and Drawer.Description, focus on open, Escape and backdrop dismiss, and focus back to restoreFocusRef or the opener after the exit. side only places the panel; it adds nothing a screen reader reads.

You supply: A name, with Drawer.Title or aria-label, and a Drawer.Close or other button that closes it. In development, an open drawer with no name logs an error. A drawer holds a longer task, so give its sections headings below the title's h2. Pass restoreFocusRef when the opener is gone by the time it closes.

Watch for: A wrapper that makes a drawer title from a plain heading leaves the drawer unnamed: wrap Drawer.Title instead, or pass aria-labelledby. While the drawer is open the page behind it is inert, so a list that filters update live beside it can't be read until it closes; announce a result count with useAnnouncer if it matters.

When to use

When: A modal side panel for a task that needs room, such as filters, settings or details beside a list. Name it with Drawer.Title or aria-label.

When not: A short centered task or confirm → Dialog. A mobile picker from the bottom → BottomSheet. A panel that leaves the page usable → product layout, not a modal.

Props

Drawer.Root props
NameTypeDescription
openboolean

Controlled open state. Leave it out for an uncontrolled drawer.

defaultOpenboolean

Shows the drawer on mount when uncontrolled. There is no trigger part, so once closed it opens again only on remount.

Default: false

onOpenChange(open: boolean, reason: DialogCloseReason) => void

Dismiss requests, with the same reasons as Dialog.Root.

side'start' | 'end'

Inline edge it is pinned to. Follows text direction.

Default: 'end'

dismissOnEscapeboolean

Escape calls onOpenChange(false, "escape").

Default: true

dismissOnBackdropboolean

Scrim click calls onOpenChange(false, "backdrop").

Default: true

aria-labelstring

Name when Drawer.Title is omitted.

Drawer.Title props
NameTypeDescription
childrenReact.ReactNode

Title text.

Drawer.Description props
NameTypeDescription
childrenReact.ReactNode

Description text.

Drawer.Close props
NameTypeDescription
aria-labelstring

Accessible name. Text of two or more letters or digits, such as "Cancel", names the button by itself. Otherwise the close string from StringsProvider names it, Close in English.

Default: "Close" when its text, not counting aria-hidden or SVG parts, has fewer than two letters or digits

onClickReact.MouseEventHandler<HTMLButtonElement>

Runs before the close request. Call event.preventDefault() to keep the drawer open.