Capítulo 13 de 43
A tri-state (checked/unchecked/indeterminate) toggle control with full keyboard support and automatic form-compatible hidden input rendering.
Root → Indicator (renders only when checked/indeterminate; wrap an icon or style directly).checked/defaultChecked accept boolean | "indeterminate" — indeterminate must be driven by controlled state (there's no defaultChecked="indeterminate" auto-toggle).Root renders a visually-hidden native input automatically so the checkbox participates in form submission/events like a real checkbox.unstable_Provider/unstable_Trigger/unstable_BubbleInput: lower-level parts (API may still change) for recomposing or excluding the hidden input.const [checked, setChecked] = React.useState("indeterminate");
<Checkbox.Root checked={checked} onCheckedChange={setChecked}>
<Checkbox.Indicator>
{checked === "indeterminate" && <DividerHorizontalIcon />}
{checked === true && <CheckIcon />}
</Checkbox.Indicator>
</Checkbox.Root>
checked, since it can't be reached through user interaction alone.| Part | Key props | Key data attributes |
|---|---|---|
Root | checked/defaultChecked (boolean | "indeterminate"), onCheckedChange, disabled, required, name, value | [data-state] (checked|unchecked|indeterminate), [data-disabled] |
Indicator | forceMount | same as Root |
defaultChecked="indeterminate" to let users toggle into indeterminate: indeterminate is a programmatic-only state — you must set it via controlled checked + onCheckedChange, users can't reach it by clicking.Checkbox works inside plain <form> submission without extra glue code.unstable_* parts if you specifically need to move/exclude the hidden input — expect their API to change in future releases.