Documentation

Checkbox

A box to check: checked, unchecked or indeterminate, with its words as one clickable label.

WebBêtaFormulaires

Web uniquement — React, depuis @krizaka/ui/checkbox. Bêta : son API peut encore changer à une version mineure.

Quand l’utiliser

  • In a form, for a choice that is submitted with it: accept the terms, subscribe to a list.
  • For several independent options in a list, and “select all” (indeterminate when some are).

Quand ne pas l’utiliser

  • For a setting that applies at once, without a submit.À la place : Switch
  • To choose one option among several.À la place : Radio group
  • To filter a list with a few options shown as pills.À la place : Chip

Installation

Installer

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Importer

import { Checkbox } from "@krizaka/ui/checkbox";

Exemples

Unchecked

Its words as children: one clickable label.

Checked

defaultChecked (or checked + onCheckedChange).

Indeterminate

checked="indeterminate": some of a list.

Disabled

Not available, checked or not.

Invalid

In a Field, with its error.

Props

A checkbox: checked/defaultChecked (true · false · "indeterminate") + onCheckedChange.

PropTypeDéfautDescription
childrenReactNode—The text next to the box, clickable: the box and its words in one <label>. Otherwise name it with Field.Label htmlFor or aria-label.
invalidboolean—Marks it invalid: aria-invalid and data-invalid (pair it with a Field.Error in aria-describedby).

Accessibilité

  • Radix Checkbox: role="checkbox" with aria-checked true, false or mixed.
  • The children are its label; without children, give it aria-label or a Field.Label htmlFor.
  • invalid sets aria-invalid; the error is read through aria-describedby.

Clavier

TouchesAction
SpaceToggles the box.

Bonnes pratiques

  • Say what checking does, in the positive: “Email me the receipts”, not “Don't email me”.
  • Pass the words as children: the whole line is the label and the click target.
  • In a Field, set invalid and point aria-describedby at the Field.Error.

Générée depuis le code de @krizaka/ui 2.0.0-beta.6 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page