Form
Checkbox
Checkbox with a built-in clickable label, controlled/uncontrolled checked state and an indeterminate (mixed) mode.
Import
import { Checkbox } from "@zephora/react";Examples
Basic
<Checkbox defaultChecked>Remember me</Checkbox> <Checkbox>Subscribe to newsletter</Checkbox> <Checkbox disabled>Disabled option</Checkbox>
Indeterminate parent
A classic select-all pattern using `indeterminate`.
const [items, setItems] = React.useState([true, false]);
const all = items.every(Boolean);
const some = items.some(Boolean) && !all;
<Checkbox
checked={all}
indeterminate={some}
onCheckedChange={(next) => setItems(items.map(() => next))}
>
Select all
</Checkbox>
{items.map((checked, i) => (
<Checkbox
key={i}
checked={checked}
onCheckedChange={(next) =>
setItems(items.map((v, j) => (j === i ? next : v)))
}
>
Item {i + 1}
</Checkbox>
))}Sizes and invalid
<Checkbox size="sm">Small</Checkbox> <Checkbox size="md">Medium</Checkbox> <Checkbox size="lg">Large</Checkbox> <Checkbox invalid>You must accept the terms</Checkbox>
API
Checkbox props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Controlled checked state. |
defaultChecked | boolean | false | Initial checked state (uncontrolled). |
onCheckedChange | (checked: boolean) => void | — | Called with the next checked state. |
indeterminate | boolean | false | Visually indeterminate ("mixed") state; also sets aria-checked="mixed". |
size | "sm" | "md" | "lg" | "md" | Control size. |
invalid | boolean | false | Marks the field invalid: sets aria-invalid and error styling. |
children | ReactNode | — | Label content; the label wraps the input so it is clickable. |
unstyled | boolean | false | Headless mode — drops Zephora classes so your own CSS can style it. |
…rest | InputHTMLAttributes<HTMLInputElement> | — | Remaining native input props (name, disabled, required…) are forwarded. |
Keyboard
| Key | Action |
|---|---|
Space | Toggles the checked state. |
Tab | Moves focus. |