Checkbox
Native checkbox with a spring-drawn check mark and an indeterminate state for select-all rows. Controlled or uncontrolled; submits with forms.
"use client";import { useState } from "react";import { Checkbox } from "@/components/ui/checkbox";import { Label } from "@/components/ui/label";export function SelectAll({ items }: { items: string[] }) { const [on, setOn] = useState<string[]>([]); const all = on.length === items.length; return ( <div className="flex items-center gap-2.5"> <Checkbox id="all" checked={all} indeterminate={on.length > 0 && !all} onCheckedChange={() => setOn(all ? [] : items)} /> <Label htmlFor="all">Select all</Label> </div> );}<Checkbox>
Native checkbox with a spring-drawn check. Controlled or uncontrolled; works inside <Field>.
checkedbooleanControlled state; pair with
onCheckedChange.defaultCheckeddefaultfalsebooleanState at first render (uncontrolled).
indeterminatedefaultfalsebooleanMixed state, e.g. a "select all" with some rows selected. Shows a dash.
onCheckedChange(checked: boolean) => voidCalled with the new state.
| Prop | Type | Default |
|---|---|---|
checkedControlled state; pair with | boolean | — |
defaultCheckedState at first render (uncontrolled). | boolean | false |
indeterminateMixed state, e.g. a "select all" with some rows selected. Shows a dash. | boolean | false |
onCheckedChangeCalled with the new state. | (checked: boolean) => void | — |
Also accepts every <input> prop.
* required. Every component also takes className.