Layout
Drawer
A sheet from the bottom of a narrow screen: a handle bar while closed, the drawer's height while open.
Installation
pnpm add @elsikora/keystone-ui-kitUsage
import { Drawer, DrawerClose, DrawerContent } from "@elsikora/keystone-ui-kit";import { Button, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerHandle, DrawerTitle,} from "@elsikora/keystone-ui-kit";
export default function DrawerDefaultExample() { return ( <div className="w-full max-w-88 border-t border-line"> <Drawer> <DrawerHandle className="tabular-nums">3 / 7 win · revealing</DrawerHandle> <DrawerContent> <DrawerClose className="tabular-nums">3 / 7 win · revealing</DrawerClose> <div className="flex flex-col gap-3 overflow-auto p-4"> <DrawerTitle>Inspector</DrawerTitle> <DrawerDescription>The round as it plays: its phase, its event and each step's timing.</DrawerDescription> <Button variant="outline">Copy the event</Button> </div> </DrawerContent> </Drawer> </div> );}Examples
Default
Beside a live page
Not modal: focus is not held and the page above stays in use.
API reference
Drawer
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Open, when the caller holds the state. |
onOpenChange | (open: boolean) => void | - | Called when it opens or closes. |
modal | boolean | true | Holds focus inside the open sheet and makes the page behind it inert. |
DrawerClose
| Prop | Type | Default | Description |
|---|---|---|---|
closeHint | string | "closes the drawer" | Read by a screen reader after the bar's text: what pressing it does. |
DrawerContent
| Prop | Type | Default | Description |
|---|---|---|---|
container | Element | DocumentFragment | null | - | Where the sheet opens; by default the nearest PortalRoot's element, else the body. |
Notes
- Enter or Space on a handle opens or closes it; Escape closes it and focus goes back to the handle.
- Modal (the default): focus stays inside the open sheet and the page behind it is inert.
- Not modal (
modal={false}): a tap or an Escape in the page is the page's; an Escape in the sheet or on its handle closes it. - The close handle's accessible name is its text and then
closeHint, so a screen reader says what pressing it does. useMediaQuery(query, serverValue)says whether the page is narrow (one subscription per query), to choose between a drawer and a column;DRAWER_SIZEgives the handle's and the sheet's heights to a page that makes room for them.- In a shadow root, a
PortalRootat the top of the tree names the element the sheet opens in; without one it opens in the document's body, which the root's sheet does not reach.SelectandAlertDialogtake it too.