Selection
Checkbox
A checkbox turns one option on or off, alone or in a group where any number can be chosen, and a parent checkbox selects a whole list at once.
In kanso-ui as Checkbox
Web and native
Checkbox in kanso-ui 0.59.0, for React.
import { Checkbox } from '@kanso-labs/kanso-ui'A checkbox with its label, and optionally a description or an error under it.
It follows the Material Design checkbox: an 18dp box with a 2dp corner inside a 40dp state layer and a 48dp target, filled with primary once selected or indeterminate, and drawn in the error pair while invalid.
What you provide
children: the label beside the box. A checkbox labelled some other way, such as by its row, leaves it out and passesaria-labelinstead.- A link or button inside the label acts on its own, as in a native label; a press anywhere else in the label toggles the box.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The label, beside the box. A checkbox that a row labels some other way leaves it out and passes `aria-label` instead. A link or a button in it acts on its own, as in a native label: a press or Enter on "the terms" in "I agree to the terms" follows the link and leaves the checkbox as it was. A press anywhere else in the label toggles it. |
description | string | — | A hint under the label. Replaced by `error` when there is one, so the two never stack. |
error | string | — | The problem with the current value, in words. Its presence is what puts the checkbox in its error state — the message, the error colours and `aria-invalid` all follow from it. Outside a `Form` the message line arrives with the message, so the field grows when this does and moves what is under it. A `Form` holds that space from the start; so does a permanent `description`. |
Also takes the props of Omit<CheckboxFieldProps, 'children' | 'isInvalid' | 'validationBehavior'>.
Example
import { Checkbox } from '@kanso-labs/kanso-ui'
<Checkbox defaultSelected description="Supporting line">
Label
</Checkbox>The design’s classes
k-check, k-group, k-group__legend, k-group--nested and k-check__reason.
Checkbox and CheckboxGroup in kanso-ui and react-native-kanso-ui, restyled to this language.