Overlays
Drawer
A side panel for filters, details or a form.
Example
Works like the dialog, but the panel takes the full height, on the right edge (placement="end", default) or the left edge (placement="start"). Its width is set with the --cr-drawer-width CSS variable (400px by default, never wider than the screen). It slides in from its edge when it opens and back out when it closes, while the background dims; without motion if the user asked to reduce motion.
'use client';
import { useState } from 'react';
import { CrButton, CrCheckbox, CrDrawer, CrInput } from '@cristal-ui/react';
export default function DrawerFilters() {
const [open, setOpen] = useState(false);
return (
<>
<CrButton variant="secondary" onClick={() => setOpen(true)}>
Filters
</CrButton>
<CrDrawer label="Filters" open={open} onCrClose={() => setOpen(false)}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--cr-spacing-lg)' }}>
<CrInput label="Maximum price" type="number" hint="In dollars" />
<CrCheckbox label="In stock only" />
</div>
<CrButton slot="footer" onClick={() => setOpen(false)}>
Apply
</CrButton>
</CrDrawer>
</>
);
}Floating, movable and resizable panel
With variant="floating", the panel comes away from the screen edges: it floats at a distance from the edge, top and bottom, with rounded corners, and slides in from beyond its edge. movable then lets the user move it on the page to see what it hides: drag its header or, with the keyboard, focus its handle (left of the title) and use the arrow keys, with Shift for bigger steps. With resizable, its size can change too: drag the bottom corner on the page side (left of a panel placed on the right) or, with the keyboard, focus that corner and use the arrow keys (left and right for the width, up and down for the height). The panel stays on screen, keeps a minimum size (280 × 200 px), and gets back its edge and size when it closes.
'use client';
import { useState } from 'react';
import { CrButton, CrDrawer, CrInput, CrTextarea } from '@cristal-ui/react';
export default function DrawerFloating() {
const [open, setOpen] = useState(false);
return (
<>
<CrButton variant="secondary" onClick={() => setOpen(true)}>
Add a note
</CrButton>
<CrDrawer label="New note" variant="floating" movable resizable open={open} onCrClose={() => setOpen(false)}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--cr-spacing-lg)' }}>
<CrInput label="Title" />
<CrTextarea label="Note" rows={4} />
</div>
<CrButton slot="footer" onClick={() => setOpen(false)}>
Save
</CrButton>
</CrDrawer>
</>
);
}Accessibility
Same guarantees as the dialog: focus trapped then restored, Escape, inert page and blocked scrolling, title as the panel's name. The handle of a movable panel is a button named "Move the panel", whose description gives the keys; so is the "Resize the panel" corner. A click on the dimmed background next to the panel closes it too; closeOnBackdrop={false} prevents it.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
closeLabel | string | — | Libellé du bouton de fermeture (« Close », ou « Fermer » en français, par défaut). |
closeOnBackdrop | boolean | true | Un clic sur le fond assombri, à côté, ferme le panneau ; false pour l'empêcher (formulaire long, confirmation). |
label (obligatoire) | string | — | Titre affiché, et nom du panneau pour les lecteurs d'écran. |
movable | boolean | false | Avec variant="floating" : le panneau se déplace en glissant son en-tête, ou avec les flèches sur sa poignée ; il revient à son bord à la fermeture. |
open | boolean | false | Ouvre ou ferme le panneau. |
placement | "end" | "start" | 'end' | Bord d'apparition : end (droite) ou start (gauche). |
resizable | boolean | false | Avec variant="floating" : la taille du panneau se change par son coin du bas (côté page), à la souris ou avec les flèches ; elle revient à l'origine à la fermeture. |
variant | "docked" | "floating" | 'docked' | Allure : docked (collé au bord, sur toute la hauteur) ou floating (détaché des bords, coins arrondis). |
Events
| React | event.detail | Description |
|---|---|---|
onCrClose | void | Émis à chaque fermeture : Échap, bouton Fermer, clic à côté (avec closeOnBackdrop) ou open à false. |
Slots
| Slot | Description |
|---|---|
| default | Contenu du panneau. |
slot="footer" | Boutons d'action. |
CSS parts
To style it from outside: cr-drawer::part(name) { … }
| Part | Description |
|---|---|
body | La zone de contenu. |
close | Le bouton Fermer. |
dialog | L'élément dialog. |
footer | La zone des actions. |
handle | La poignée de déplacement (avec movable). |
resize | La poignée de redimensionnement (avec resizable). |
title | Le titre. |