Checkbox
A composable tri-state checkbox with separate checked and indeterminate bindings, hidden input form support, and headless indicator rendering.
Anatomy
The checkbox is assembled from two parts. Checkbox.Root renders the control (and a hidden checkbox input for form integration); Checkbox.Indicator renders the check or mixed mark and only mounts while the checkbox is checked or indeterminate.
<script>
import { Checkbox } from '@human-kit/ui';
</script>
<Checkbox.Root aria-label="Accept terms">
<Checkbox.Indicator>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Root>States
Every visual state is exposed through data-* attributes on both parts, so all styling — including disabled, readonly, and indeterminate — is done with plain CSS or utility classes.
Indeterminate
The mixed state has its own indeterminate / defaultIndeterminate binding and takes precedence over checked. The first user toggle from the indeterminate state resolves to checked.
Forms
Checkbox.Root keeps a hidden checkbox input in sync: give it a name and value and the pair is submitted when the checkbox is checked. Unchecked and indeterminate states submit no entry.
Usage guidelines
- Use
checked/defaultCheckedfor the checked state andindeterminate/defaultIndeterminatefor the mixed state. indeterminatetakes precedence overchecked. When both aretrue, the checkbox is exposed as indeterminate.- Use
valueonly for form submission through the hidden native input; it does not represent the visual state. - Wrap the checkbox in a native
<label>for the simplest accessible labeling pattern, or point a siblinglabel[for]at the checkboxid.
Accessibility
Checkbox.Rootexposesrole="checkbox"witharia-checked="true" | "false" | "mixed".- Press
Spaceto toggle the checkbox. readonlykeeps the checkbox focusable while preventing state changes.
API reference
Root
The checkbox control. Renders a span with role="checkbox" and keeps a hidden checkbox input in sync for form integration.
* required. Native HTML attributes of the underlying element are also accepted.
Indicator
The visual check or mixed mark. Only mounted while the checkbox is checked or indeterminate unless `forceMount` is set.
* required. Native HTML attributes of the underlying element are also accepted.