Actions
Inline confirmation
The button of a risky action turns into a question in place.
Example
cr-confirm wraps the button of an action one might regret. On click, the button gives way to a question (question) and two buttons: the one that confirms (confirmLabel, "Confirm" by default) and Cancel. The action runs in onCrConfirm.
'use client';
import { useState } from 'react';
import { CrBox, CrButton, CrConfirm } from '@cristal-ui/react';
export default function ConfirmBasic() {
const [files, setFiles] = useState(['march-report.pdf', 'client-quote.docx', 'team-photo.jpg']);
return (
<CrBox display="flex" direction="column" gap="sm" align="start">
{files.map((file) => (
<CrBox key={file} display="flex" gap="lg" align="center">
<span style={{ minWidth: 160 }}>{file}</span>
<CrConfirm question={`Delete ${file}?`} confirmLabel="Delete" onCrConfirm={() => setFiles((all) => all.filter((name) => name !== file))}>
<CrButton size="s" variant="outline">
Delete
</CrButton>
</CrConfirm>
</CrBox>
))}
<span role="status">{files.length === 0 ? 'All files have been deleted.' : ''}</span>
</CrBox>
);
}When to use it
For a one-off action in a list or a table row (delete a file, remove a member), the inline confirmation avoids interrupting the page. For a heavy action whose consequences need explaining, prefer a dialog.
The confirm button carries the action verb ("Delete"), not a mere "Yes": users know what they accept without reading the question again.
If the user asked their system to reduce motion, the question appears directly, without sliding.
Accessibility
- The question and its two buttons form a group named by the question, read when focus enters it.
- Focus goes to Cancel: two quick presses on Enter are not enough to confirm by mistake.
- Escape or Cancel bring back the original button and move focus back to it; focus moving elsewhere also cancels the question.
- Inside a dialog, Escape cancels the question without closing the dialog.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
cancelLabel | string | — | Libellé du bouton qui annule ; « Annuler » par défaut. |
confirmLabel | string | — | Libellé du bouton qui confirme, le verbe de l'action (« Supprimer ») ; « Confirmer » par défaut. |
question (obligatoire) | string | — | Question posée à la place du bouton, courte et précise : « Supprimer ce fichier ? » (obligatoire). |
Events
| React | event.detail | Description |
|---|---|---|
onCrConfirm | void | Émis quand l'utilisateur confirme : c'est là que l'action s'exécute. |
Slots
| Slot | Description |
|---|---|
| default | Le bouton qui déclenche l'action : cr-button, cr-icon-button ou bouton natif. |
CSS parts
To style it from outside: cr-confirm::part(name) { … }
| Part | Description |
|---|---|
cancel | Le bouton qui annule. |
confirm | Le bouton qui confirme. |
question | La question. |