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.
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.
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}.
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
| Name | Type | Default | Description |
|---|---|---|---|
placement | "left" | "right" | "top" | "bottom" | "right" | Edge of the screen the drawer slides in from. |
dismissable | boolean | true | Closes the drawer when the user clicks outside it or presses Esc. |
isKeyboardDismissDisabled | boolean | !dismissable | Prevents 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).