[ Forms ]
Checkbox
A checkbox with an optional label and description. Supports the indeterminate state for "select all" patterns and works controlled or uncontrolled like a native checkbox.
Import#
import { Checkbox } from 'reusify-ui';When to use#
- Turning a single option on or off as part of a form that is submitted later, such as "I accept the terms".
- Choosing any number of items from a list.
- For a setting that applies immediately, use a Switch instead.
Examples#
Basic#
<Checkbox label="Accept terms and conditions" defaultChecked />
<Checkbox label="Subscribe to newsletter" />
<Checkbox label="Disabled option" disabled />With description#
description adds secondary text under the label.
<Checkbox
label="Marketing emails"
description="Product news and tips, about once a month."
/>Colors#
color sets the checked fill, the indeterminate dash and the focus ring. Colors come from the theme tokens, so they follow your brand and dark mode.
<Checkbox color="primary" label="Primary" defaultChecked />
<Checkbox color="secondary" label="Secondary" defaultChecked />
<Checkbox color="success" label="Success" defaultChecked />
<Checkbox color="danger" label="Danger" defaultChecked />
<Checkbox color="warning" label="Warning" defaultChecked />
<Checkbox color="info" label="Info" defaultChecked />
<Checkbox color="success" label="Partially done" indeterminate />Indeterminate (select all)#
indeterminate shows a dash when only some children are selected. Click the items to see it change.
Used in designs#
Checkbox in real layouts: these 2 designs use it. Open one to try it and copy the code.
API reference#
<Checkbox />
Also accepts native checkbox attributes (checked, defaultChecked, onChange, name, value…) and forwards its ref to the <input>.
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | - | Clickable label next to the box. |
description | ReactNode | - | Secondary text below the label. |
indeterminate | boolean | false | Shows a dash for a partially selected group. |
color | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'primary' | Checked fill and focus ring color. |
disabled | boolean | false | Disables the checkbox. |
label-ReactNodeClickable label next to the box.
description-ReactNodeSecondary text below the label.
indeterminatefalsebooleanShows a dash for a partially selected group.
color'primary''primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info'Checked fill and focus ring color.
disabledfalsebooleanDisables the checkbox.
Accessibility#
- A native <input type="checkbox"> inside a <label>, so clicking the text toggles it and Space works.
- indeterminate is set on the DOM node, so screen readers announce "mixed".