Checkbox

Web/Mobile

A control that toggles between checked, unchecked, and indeterminate. Compose with Label via id and htmlFor.

Installation

pnpm dlx cubix-ui@latest add checkbox --base radix

Usage

Import
import { Label } from "@/components/cubix/label"
import { Checkbox } from "@/components/cubix/checkbox"
Example
<div className="flex items-center gap-2">
  <Checkbox id="checkbox-demo-terms" defaultChecked />
  <Label htmlFor="checkbox-demo-terms">پذیرش قوانین و شرایط</Label>
</div>

Composition

Checkbox is the control only. Pair it with Label using matching id and htmlFor. Use indeterminate for partial selection and aria-invalid for error states.

Structure
div
├── Checkbox (id)
└── Label (htmlFor)

Accessibility

Every base exposes a native checkbox role with aria-checked, including the mixed state for indeterminate. Space toggles the focused control, and clicking the Label toggles it too. Link helper or error text with aria-describedby, and group related options in a fieldset with a legend. While pending is set the control is disabled and reports aria-busy.

Examples

With description

Add a helper line for consent and settings rows, linked with aria-describedby.

ماهی یک ایمیل درباره قابلیت‌های جدید و تغییرات مهم دریافت می‌کنید.

Indeterminate

A parent checkbox shows indeterminate while only some children are selected, and toggles all of them at once.

دسترسی‌های عضو

Invalid

Set aria-invalid when a required choice is missing. The control gets a destructive border and ring; show the error copy below it.

برای ادامه باید قوانین را بپذیرید.

Disabled

Disabled checkboxes cannot be toggled. Checked and indeterminate controls fade to reduced opacity.

Pending

Set pending while a save is in flight. The square is replaced by a circular spinner and interaction is blocked until the request finishes.

Form

Give each checkbox a name and value so checked options are submitted with the form.

کانال‌های اعلانانتخاب کنید پیام‌ها از چه راهی به شما برسد.

API Reference

Note: Parts render data-slot attributes (checkbox, checkbox-indicator) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

Checkbox

PropTypeDefaultDescription
checkedboolean-Controlled checked state. Pair with onCheckedChange when the parent owns the value.
defaultCheckedbooleanfalseInitial checked state for uncontrolled usage.
onCheckedChange(checked: boolean) => void-Called with the next boolean value whenever the checkbox is toggled.
indeterminatebooleanfalseShows the mixed state (minus icon). Use for partial selection in grouped options.
disabledbooleanfalseDisables the control and blocks interaction.
pendingbooleanfalseShows a circular spinner in place of the box while a save is in flight. Blocks interaction and sets aria-busy.
requiredbooleanfalseMarks the control as required for form validation.
namestring-Name submitted with the form when the checkbox is checked.
valuestring"on"Value submitted with the form when the checkbox is checked.
idstring-Associates the control with a Label through htmlFor for accessible naming.
aria-invalidbooleanfalseMarks the control as invalid. Adds a destructive border and ring; link the error text with aria-describedby.
classNamestring-Additional Tailwind classes merged with the control styles (last one wins).

States

PropTypeDefaultDescription
checked--Primary fill with a check icon.
indeterminate--Primary fill with a minus icon for partial selection.
disabled--Unchecked stays full opacity; checked or indeterminate use reduced opacity.
pending--Borderless control with a spinning loader; interaction is blocked.
aria-invalid--Destructive border and ring. Show error copy below the control.