Skip to Content
Cristal

Forms

Checkbox

Yes/no choice or multiple selection.

<cr-checkbox>CrCheckbox

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.
  • indeterminate is announced as "partially checked".

API

Properties

PropertyTypeDefaultDescription
checkedbooleanfalseÉtat coché.
disabledbooleanfalseDésactive la case.
errorstring—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.
hintstring—Texte d'aide, lu par les lecteurs d'écran.
indeterminatebooleanfalseÉtat partiellement coché, par exemple pour « tout sélectionner ».
label (obligatoire)string—Libellé affiché à côté de la case.
namestring—Nom envoyé avec le formulaire.
requiredbooleanfalseRend la case obligatoire.
valuestring'on'Valeur envoyée quand la case est cochée.

Events

Reactevent.detailDescription
onCrChangebooleanÉmis quand la case change ; detail : l'état coché.

CSS parts

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

PartDescription
controlLa case native.
errorLe message d'erreur.
hintLe texte d'aide.
labelLe libellé.

On this page