Checkbox
npx shadcn add @klarhimmel/checkboxCopy for AIExamples
States
Group
Invalid
DetailsAbout, usage, props and more
A box that is on, off or mixed, with its label inside a 44 px row. Built on Radix Checkbox.
When to use
Use for
Choices that are submitted with a form, and lists where several can be picked.
Not for
A setting that applies right away. Use Switch.
Pairs with
Field rows, fieldset and legend, Button.
Preview
Anyone in your organisation can see it.
You need to accept the terms to continue.
Import
Import
- Files
- checkbox.tsx, in components/klarhimmel/ui/. With it: theme, utils. npm: lucide-react.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | - | Visible label. Without one, pass aria-label. |
hint | ReactNode | - | Help text under the label, wired as the description. |
invalid | boolean | - | Marks the box invalid; the hint turns into the error text. |
checked | boolean | 'indeterminate' | - | Controlled or uncontrolled state. "indeterminate" shows a dash. |
defaultChecked | boolean | false | Controlled or uncontrolled state. "indeterminate" shows a dash. |
onCheckedChange | (checked: boolean) => void | - | Called when the state changes. |
name | string | - | With a name, the checkbox posts `value` (default "on") when checked. |
value | string | 'on' | |
required | boolean | - | |
native attributes | ButtonHTMLAttributes | - | Every native attribute of the element passes through, className included. |
Accessibility
| Key | Does |
|---|---|
Space | Checks or unchecks |
Tab | Moves focus; the ring is always visible |
A group needs a fieldset and legend so the question is read with each box.
Accessibility