Checkbox

Native checkbox with optional label and description, including indeterminate.

Also known as: tick box, indeterminate checkbox

Installation

Install with the CLI, or copy the component source into your project.

Add checkbox (npm)

npx --yes -p @default-file/ui df-ui add checkbox

Default

Labeled checkbox in the checked state.

Label and description

Visible label with supporting text. Description is wired as aria-describedby on the input.

Indeterminate

Parent mixed state when some child items are selected. Clicks commit true or false; the parent sets indeterminate.

Sizes

Control sizes sm and md. Default is md.

Disabled

Non-interactive off and on states.

Invalid

Invalid chrome with aria-invalid on the input.

Properties

Native checkbox with optional label and description, supporting checked, unchecked, and indeterminate.

Checkbox

PropTypeDefaultNotes
checkedboolean | "indeterminate"-Controlled state. Pass "indeterminate" for the mixed visual and aria-checked="mixed".
defaultCheckedbooleanfalseUncontrolled initial checked state.
onCheckedChange(checked: boolean | "indeterminate") => void-Called when the user toggles. Interaction always commits true or false; indeterminate is set from the parent.
size"sm" | "md""md"Control size.
invalidbooleanfalseMarks the control invalid and sets aria-invalid.
labelReactNode-Visible label. When set (or description is set), the control wraps in a label element bound with htmlFor.
descriptionReactNode-Supporting text under the label. Wired as aria-describedby on the input.
disabledboolean-Disables the input.
idstring-Input id. Generated when omitted.
namestring-Form name on the input.
valuestring-Form value on the input.
requiredboolean-Native required on the input.
classNamestring-Additional styles on the field wrapper when label or description is set, otherwise on the control root.

Accessibility

Pass label for a visible name, or supply aria-label or aria-labelledby on the input when rendering the control alone. Also accepts other native input attributes except type, size, checked, defaultChecked, and onChange; use onCheckedChange for selection changes.