Skip to Content
Cristal

Overlays

Drawer

A side panel for filters, details or a form.

<cr-drawer>CrDrawer

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.

Filters
Apply
'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.

Add a note
Save
'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

PropertyTypeDefaultDescription
closeLabelstring—Libellé du bouton de fermeture (« Close », ou « Fermer » en français, par défaut).
closeOnBackdropbooleantrueUn 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.
movablebooleanfalseAvec 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.
openbooleanfalseOuvre ou ferme le panneau.
placement"end" | "start"'end'Bord d'apparition : end (droite) ou start (gauche).
resizablebooleanfalseAvec 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

Reactevent.detailDescription
onCrClosevoidÉmis à chaque fermeture : Échap, bouton Fermer, clic à côté (avec closeOnBackdrop) ou open à false.

Slots

SlotDescription
defaultContenu du panneau.
slot="footer"Boutons d'action.

CSS parts

To style it from outside: cr-drawer::part(name) { … }

PartDescription
bodyLa zone de contenu.
closeLe bouton Fermer.
dialogL'élément dialog.
footerLa zone des actions.
handleLa poignée de déplacement (avec movable).
resizeLa poignée de redimensionnement (avec resizable).
titleLe titre.

On this page