Checkbox

A control for a binary or tri-state choice, built on Radix Checkbox. Supports the indeterminate state a “select all” needs. It's the same control the DataTable uses for row selection.

Installation#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Add this component (its dependencies come along)npx koalaui-cli@latest add checkbox

Usage#

usage.tsxTSX
import { Checkbox } from "@/components/ui/checkbox"export function Example() {  return (    <label htmlFor="terms" className="flex items-center gap-2.5">      <Checkbox id="terms" defaultChecked />      Accept terms and conditions    </label>  )}

Anatomy#

import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox"<Checkbox /><CheckboxGroup allValues={[…]}>  <Checkbox parent />  <Checkbox value="…" />  <CheckboxGroup allValues={[…]}>    <Checkbox parent />    <Checkbox value="…" />  </CheckboxGroup></CheckboxGroup>

States#

Checked and indeterminate both fill with the primary (ink) color; indeterminate shows a minus rather than a check. Drive the tri-state by passing checked="indeterminate".

Unchecked
Checked
Indeterminate
Disabled
Disabled checked

Sizes#

sm (16px) sits inside dense tables; md (20px) is the default for forms. The indicator scales with the box.

sm
md

With a label#

Checkbox renders only the box; pair it with a <label htmlFor> for an accessible name and a larger hit target. With a description, nudge the box to the first line.

Group#

CheckboxGroup holds one string[] for a whole set. Each member is a plain Checkbox with a value, so there is no per-box state to keep. Use defaultValue, or value with onValueChange to control it. Name the group with aria-labelledby.

Notify me by

Select all#

Pass allValues and add a Checkbox parent. It reads checked when every child is, indeterminate on a partial selection and unchecked when none are, and a click toggles them all. From a partial selection it cycles through all, none, then back to the selection you had, so a stray click never loses it. The same tri-state the DataTable header uses.

1 of 3 selected

Nested#

Put a CheckboxGroup inside another and leave out its value: it shares the outer group’s list and only scopes its own allValues. A tree of permissions stays one flat array, and every parent at every level follows its children with no wiring.

API reference#

Checkbox

The box, Radix Checkbox.Root. Renders a <button role="checkbox"> and forwards all its props. Pair it with a <label htmlFor>.

PropTypeDefaultDescription
checkedboolean | "indeterminate"-Controlled state. Ignored inside a CheckboxGroup, where the group decides.
defaultCheckedboolean | "indeterminate"falseInitial state when uncontrolled.
onCheckedChange(checked: boolean | "indeterminate") => void-Called when the box toggles, inside a group too.
valuestring"on"The form value. Inside a CheckboxGroup it is also the member's identity in the group's list.
parentbooleanfalseInside a CheckboxGroup: governs the group's allValues, reading checked, indeterminate or unchecked from them.
size"sm" | "md""md"16px for dense tables, 20px for forms.
disabledbooleanfalseDisables the box. Falls back to the group's, then the Field's.
namestring-Submitted with the form when checked.
requiredbooleanfalseMarks the box required in a form.
Data attributeDescription
data-state"checked", "unchecked" or "indeterminate".
data-disabledPresent when disabled.
data-parentPresent on a parent box inside a group.

CheckboxGroup

A set of checkboxes sharing one string[]. Renders a <div role="group">, a column with a 12px gap; name it with aria-labelledby or aria-label. Forwards all native <div> props.

PropTypeDefaultDescription
valuestring[]-The checked values (controlled).
defaultValuestring[][]The values checked at first (uncontrolled).
onValueChange(value: string[]) => void-Called with the new list when a member or a parent toggles.
allValuesstring[]-Every value the group's parent box governs. Required for a parent. On a nested group, its slice of the outer list.
disabledbooleanfalseDisables every checkbox in the group.
Data attributeDescription
data-disabledPresent when the group is disabled.

FAQ#

Use a Checkbox for selecting items in a set or accepting terms, especially where a tri-state or select-all is involved. Use a Switch for toggling a single setting on or off that takes effect immediately.