Skip to content
Ginga UI
Ginga UI
日本語

Getting started

  • Overview
  • Quick start
  • Theme generation
  • Custom rendering
  • All components

Forms

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

Display

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

Typography

  • Heading
  • Paragraph

Navigation

  • Anchor

Layout

  • Box

Resources

  • Changelog
  • GitHub (opens in a new tab)

Logo: Twemoji (opens in a new tab) (CC-BY 4.0)

Drawer

A drawer that slides in from the edge of the screen. Supports four placements (left, right, top, bottom) and a non-modal mode that stays open while the page remains interactive.

View in Storybook (opens in a new tab)

Installation

import { Drawer } from "@ginga-ui/core";

Basic usage

A drawer that slides in from the right edge of the screen.

drawer.tsx
drawer.module.css
import { Button, DialogTrigger, Drawer, DrawerContent, DrawerTitle } from "@ginga-ui/core";
import { Menu, X } from "lucide-react";
import styles from "./drawer.module.css";

export function BasicExample() {
  return (
    <DialogTrigger>
      <Button variant="filled" startIcon={<Menu />}>
        Open menu
      </Button>
      <Drawer>
        <DrawerContent>
          <DrawerTitle>Menu</DrawerTitle>
          <p>A drawer that slides in from the right.</p>
          <div className={styles.actions}>
            <Button slot="close" variant="outline" startIcon={<X />}>
              Close
            </Button>
          </div>
        </DrawerContent>
      </Drawer>
    </DialogTrigger>
  );
}

Placement

Use the placement prop to choose from four directions: left, right, top, and bottom.

drawer.tsx
drawer.module.css
import { Button, DialogTrigger, Drawer, DrawerContent, DrawerTitle } from "@ginga-ui/core";
import { X } from "lucide-react";
import styles from "./drawer.module.css";

export function PlacementsExample() {
  return (
    <div className={styles.placementRow}>
      {(["left", "right", "top", "bottom"] as const).map((placement) => (
        <DialogTrigger key={placement}>
          <Button variant="outline">{placement}</Button>
          <Drawer placement={placement}>
            <DrawerContent>
              <DrawerTitle>{placement}</DrawerTitle>
              <p>A drawer that appears from the {placement}.</p>
              <div className={styles.actions}>
                <Button slot="close" variant="outline" startIcon={<X />}>
                  Close
                </Button>
              </div>
            </DrawerContent>
          </Drawer>
        </DialogTrigger>
      ))}
    </div>
  );
}

Not dismissed by outside click

Pass false to dismissable to keep the drawer open when clicking outside or pressing the Esc key. It closes only with the close button. To allow the Esc key, pass isKeyboardDismissDisabled={false}.

drawer.tsx
drawer.module.css
import { Button, DialogTrigger, Drawer, DrawerContent, DrawerTitle } from "@ginga-ui/core";
import { PanelRight, X } from "lucide-react";
import styles from "./drawer.module.css";

export function NotDismissableExample() {
  return (
    <DialogTrigger>
      <Button variant="light" startIcon={<PanelRight />}>
        Stay open on outside click
      </Button>
      <Drawer dismissable={false}>
        <DrawerContent>
          <DrawerTitle>Confirmation required</DrawerTitle>
          <p>The drawer stays open until you press the close button.</p>
          <div className={styles.actions}>
            <Button slot="close" variant="filled" startIcon={<X />}>
              Close
            </Button>
          </div>
        </DrawerContent>
      </Drawer>
    </DialogTrigger>
  );
}

Props

Drawer

NameTypeDefaultDescription
placement"left" | "right" | "top" | "bottom""right"Edge of the screen the drawer slides in from.
dismissablebooleantrueCloses the drawer when the user clicks outside it or presses Esc.
isKeyboardDismissDisabledboolean!dismissablePrevents closing the drawer with Esc.

Also accepts the props of React Aria's ModalOverlay (opens in a new tab).

DrawerContent

Accepts the props of React Aria's Dialog (opens in a new tab).

DrawerTitle

Accepts the props of React Aria's Heading (opens in a new tab).