Overlays
Dialog
A window that interrupts the page for a decision or a short input.
Example
The content goes in the default slot, the action buttons in slot="footer". Control opening with open, and set your state back to false in onCrClose.
This action cannot be undone.
'use client';
import { useState } from 'react';
import { CrButton, CrDialog } from '@cristal-ui/react';
export default function DialogConfirm() {
const [open, setOpen] = useState(false);
const [status, setStatus] = useState('');
return (
<>
<CrButton onClick={() => setOpen(true)}>Delete product</CrButton>
<span role="status">{status}</span>
<CrDialog label="Delete this product?" open={open} onCrClose={() => setOpen(false)}>
<p>This action cannot be undone.</p>
<CrButton slot="footer" variant="secondary" onClick={() => setOpen(false)}>
Cancel
</CrButton>
<CrButton
slot="footer"
onClick={() => {
setStatus('Product deleted.');
setOpen(false);
}}
>
Delete
</CrButton>
</CrDialog>
</>
);
}Accessibility
Cristal uses the native <dialog> element opened in modal mode:
- focus moves into the window when it opens, stays trapped inside, and returns to the opening button when it closes;
- Escape closes the window; a click on the dimmed background next to it closes it too;
closeOnBackdrop={false}prevents it, for example for a long form that a stray click would lose; - the rest of the page becomes inert (neither clickable nor readable by screen readers) and no longer scrolls;
- the title (
label) is used as the window's name; the close button is labelled "Close", or "Fermer" on a French page (customizable withcloseLabel).
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 la fenêtre ; false pour l'empêcher (formulaire long, confirmation). |
label (obligatoire) | string | — | Titre affiché, et nom de la fenêtre pour les lecteurs d'écran. |
open | boolean | false | Ouvre ou ferme la fenêtre. |
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 de la fenêtre. |
slot="footer" | Boutons d'action. |
CSS parts
To style it from outside: cr-dialog::part(name) { … }
| Part | Description |
|---|---|
body | La zone de contenu. |
close | Le bouton Fermer. |
dialog | L'élément dialog. |
footer | La zone des actions. |
title | Le titre. |