Checkbox
Checkbox turns a single option on or off.
<Checkbox id="ship" defaultChecked /><Text render={<label htmlFor="ship" />}>Ship it</Text>Checkbox turns a single option on or off. It is neutral when off and takes the accent colour when on, and it can also show a mixed state for a group where only some options are selected.
Use a checkbox for an option that takes effect when you submit a form, or for choosing several items from a list. For a setting that takes effect straight away, use a Switch. To pick one option from several, use a RadioGroup, and for a pressed state in a toolbar, use a Toggle.
The label is a separate element rather than a child. In a form, put each checkbox in a FieldItem with a FieldLabel, and add a FieldDescription if the option needs explaining. Outside a form, give the checkbox an id and render a Text as <label htmlFor>. A label that wraps the checkbox works too, such as <Card render={<label />}>.
Use defaultChecked to let the checkbox hold its own state, or checked with onCheckedChange when your app holds it. Set indeterminate for the mixed state, and name to send the value with a form. There is no readOnly, so use disabled for an option that can't be changed.
The box is as tall as one line of the text beside it, so it lines up with its label. size sets that height, and when you don't set it the checkbox takes the size of its Field or else the Theme's size. The area you can tap reaches beyond the visible box to the height of a Button at the same size. When you stack checkboxes, keep at least gap="5" between them so those tap areas don't overlap.
Space toggles a focused checkbox, and clicking its label toggles it too. A screen reader reads the label and the state: checked, not checked or mixed. A focus ring shows when you reach the checkbox with the keyboard.
- Switch when the setting takes effect the moment it changes.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
size? | "1" | "2" | "3" | "4" | The size step of the checkbox, from 1 to 4. |
toneandemphasis— A checkbox always means the same thing, so it is always neutral when off and accent when on. If one option needs to stand out, say so in its label.children— The label is a sibling element rather than a child, so the layout around them decides the space between the box and its label.readOnly— HTML has no read-only checkbox, and one would look exactly like a live checkbox that ignores presses. Usedisabledfor an option that can't be changed.