Checkbox
Boolean selection control with labels, descriptions, errors, and indeterminate state
Checkbox is a native checkbox with a styled control, label, supporting description, validation message, disabled state, and indeterminate state.
It supports three visual sizes—default, sm, and xs—plus a loading state and optional custom icons for checked or indeterminate states.
Basic usage
import { Checkbox } from '@mosmox/ui';
<Checkbox label="Send me product updates" />The component forwards native checkbox attributes such as name, value, required, checked, defaultChecked, disabled, and onChange.
Controlled and uncontrolled values
Use defaultChecked for an uncontrolled checkbox:
<Checkbox label="Accept terms" defaultChecked />Use checked and onChange when the parent owns the value:
const [accepted, setAccepted] = useState(false);
<Checkbox
label="Accept terms"
checked={accepted}
onChange={(event) => setAccepted(event.target.checked)}
/>Description and validation
<Checkbox
label="Share analytics"
description="Helps us improve the product."
/>
<Checkbox
label="Accept terms"
error="You must accept the terms to continue."
required
/>Descriptions and errors are connected through aria-describedby; an error also sets aria-invalid unless explicitly overridden.
Indeterminate state
Use indeterminate for a parent selection whose children are only partly selected. This is a visual and native checkbox state; the parent should still manage the selected-child logic.
<Checkbox label="Select all projects" indeterminate />Sizes
<Checkbox label="Default" size="default" />
<Checkbox label="Small" size="sm" />
<Checkbox label="Extra small" size="xs" />Custom state icons
Pass checkedIcon or indeterminateIcon when the default checkmark or dash should be replaced by an icon or another React node.
import { Check, Minus } from '@mosmox-ui/icons';
<Checkbox label="Verified" checked defaultChecked checkedIcon={<Check />} />
<Checkbox label="Partially selected" indeterminate indeterminateIcon={<Minus />} />Loading state
Set loading while saving a checkbox change. The control becomes disabled and shows a spinner until the parent turns loading off.
<Checkbox label="Saving preference…" checked loading />Disabled state
<Checkbox label="Unavailable option" disabled />
<Checkbox label="Disabled and selected" disabled defaultChecked />Disabled checkboxes cannot receive normal user interaction and use the shared disabled opacity token treatment.
Accessibility
- the visible label is associated with the native checkbox through the wrapping label;
- keyboard focus uses a visible focus ring;
required,disabled,checked, andindeterminatepreserve native checkbox semantics;- descriptions and errors are announced through
aria-describedby; - use a label that describes the choice instead of relying on visual context alone.
Styling model
Checkbox colors, typography, focus, surface, and disabled treatment use shared theme tokens. Checkbox-only geometry and checkmark drawing are in Checkbox.css.
API Reference
| Property | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | Visible checkbox label. |
description | string | — | Supporting text below the option. |
error | string | — | Validation message and error state. |
size | default | sm | xs | default | Visual size. |
indeterminate | boolean | false | Displays the partial-selection state. |
checkedIcon | ReactNode | — | Replaces the default checkmark when checked. |
indeterminateIcon | ReactNode | — | Replaces the default dash when indeterminate. |
loading | boolean | false | Disables the control and shows a saving spinner. |
checked | boolean | — | Controlled checked state. |
defaultChecked | boolean | false | Initial uncontrolled checked state. |
onChange | ChangeEventHandler<HTMLInputElement> | — | Native checkbox change handler. |
required | boolean | false | Enables native required validation. |
disabled | boolean | false | Disables interaction. |
name | string | — | Form submission name. |
value | string | on | Form submission value. |
id | string | generated | Checkbox ID. |
aria-describedby | string | generated | Additional description IDs. |
aria-invalid | `boolean | 'true' | 'false'` |
Other supported native checkbox input attributes are forwarded to the underlying <input>.