Forms
Checkbox
Yes/no choice or multiple selection.
Examples
import { CrCheckbox } from '@cristal-ui/react';
export default function CheckboxBasic() {
return (
<>
<CrCheckbox label="Subscribe to the newsletter" name="newsletter" hint="One email a month, unsubscribe in one click." />
<CrCheckbox label="Select all" indeterminate />
<CrCheckbox label="Unavailable option" disabled />
<CrCheckbox label="I accept the terms" error="You must accept the terms to continue." />
</>
);
}In a form
A checked box submits its value (on by default) under its name; an unchecked box submits nothing, like a native checkbox. See the full example on the Text field page.
error-animation animates the error when it appears and on every rejected submit (zigzag, badge, echo…): see Animated error.
Accessibility
- Native checkbox under the hood: checked with Space, announced as "checkbox, checked / not checked".
- The label is clickable and enlarges the click area.
indeterminateis announced as "partially checked".
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | État coché. |
disabled | boolean | false | Désactive la case. |
error | string | — | Message d'erreur ; remplace le message automatique de validation. |
errorAnimation | "drop" | "echo" | "jitter" | "none" | "pop" | "wobble" | "zigzag" | 'none' | Animation de l'erreur quand elle apparaît et à chaque envoi refusé : none (par défaut), zigzag, pop, drop, echo, jitter ou wobble. |
hint | string | — | Texte d'aide, lu par les lecteurs d'écran. |
indeterminate | boolean | false | État partiellement coché, par exemple pour « tout sélectionner ». |
label (obligatoire) | string | — | Libellé affiché à côté de la case. |
name | string | — | Nom envoyé avec le formulaire. |
required | boolean | false | Rend la case obligatoire. |
value | string | 'on' | Valeur envoyée quand la case est cochée. |
Events
| React | event.detail | Description |
|---|---|---|
onCrChange | boolean | Émis quand la case change ; detail : l'état coché. |
CSS parts
To style it from outside: cr-checkbox::part(name) { … }
| Part | Description |
|---|---|
control | La case native. |
error | Le message d'erreur. |
hint | Le texte d'aide. |
label | Le libellé. |