form
A checkbox for a yes or no choice, or for picking several items from a list.
npx blankui add checkboxAbout once a month.
Built on Radix. Use checked and onCheckedChange, not onChange. The value can be true, false or "indeterminate".
import { Checkbox } from "@/components/ui/checkbox"
<Field label="Send me product updates" orientation="horizontal">
<Checkbox checked={updates} onCheckedChange={(checked) => setUpdates(checked === true)} />
</Field>
<Field label="I agree to the terms" orientation="horizontal" required>
<Checkbox name="terms" value="yes" />
</Field>
| Avoid | Instead |
|---|---|
| <input type="checkbox"> | <Checkbox> |
| onChange={(e) => setValue(e.target.checked)} | onCheckedChange={(checked) => setValue(checked === true)} |
| <Field label="..."> (vertical) around a Checkbox | <Field label="..." orientation="horizontal"> |
Install with the shadcn CLI: npx shadcn add https://blank.vageshwar.dev/r/checkbox.json