A native checkbox, restyled: label and description, an indeterminate state, two sizes, and CheckboxGroup with an optional select-all row.
Used for
- Accept terms
- Pick tools for an agent
- Select all rows
- Notification options
Examples
Installation
npx knowns-ui@latest add checkboxFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Checkbox from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/checkbox
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add checkbox
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/checkbox.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/checkbox, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "checkbox" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- label / description
ReactNode- Clicking the label toggles the box.
- indeterminate
boolean- Default
false - Shows a dash; screen readers hear “mixed”. A click still toggles checked.
- size
"sm"|"md"- Default
"md" - 14 or 16px box.
- …input props
checked, defaultChecked, onChange, disabled, name…- Everything else goes to the native input.
| Prop | Type | Default | Description |
|---|---|---|---|
| label / description | ReactNode | - | Clicking the label toggles the box. |
| indeterminate | boolean | false | Shows a dash; screen readers hear “mixed”. A click still toggles checked. |
| size | "sm" | "md" | "md" | 14 or 16px box. |
| …input props | checked, defaultChecked, onChange, disabled, name… | - | Everything else goes to the native input. |
- CheckboxGroup legend / description
ReactNode- On a fieldset and legend, so the group is named.
- options
{ value, label, description?, disabled? }[]- One checkbox each.
- value / defaultValue / onValueChange
string[] / string[] / (values) => void- Default
[] - The checked values.
- selectAll
string- Label of a parent row that checks or clears every enabled option, with a dash when only some are on.
- name / size / disabled
string / "sm"|"md" / boolean- Passed to every checkbox.
| Prop | Type | Default | Description |
|---|---|---|---|
| CheckboxGroup legend / description | ReactNode | - | On a fieldset and legend, so the group is named. |
| options | { value, label, description?, disabled? }[] | - | One checkbox each. |
| value / defaultValue / onValueChange | string[] / string[] / (values) => void | [] | The checked values. |
| selectAll | string | - | Label of a parent row that checks or clears every enabled option, with a dash when only some are on. |
| name / size / disabled | string / "sm" | "md" / boolean | - | Passed to every checkbox. |
What it handles
- 01Restyles a native checkbox, so form submission, the label click and the keyboard work as the browser defines them.
- 02Shows a dash and reports aria-checked mixed through the indeterminate prop, which it sets on the DOM property in an effect.
- 03Adds a label and a muted description beside the box, in sm 14px or md 16px, and dims both when the box is disabled.
- 04Reads the checked and indeterminate colour from --kn-accent, falling back to --primary.
- 05Ships CheckboxGroup, a fieldset with a legend, a description, a name that submits one entry per checked value, and a group-wide disabled flag.
- 06Gives CheckboxGroup a select-all row whose box is checked, dashed or empty from selectAllState, and toggleAll leaves disabled options as they are.
States
- First render
- Nothing. The box paints in its checked or empty state
- none
- Check
- The fill takes the accent colour and the tick scales in from 90% while fading in
- 120ms, ease out
- Uncheck
- The fill and the tick fade back out
- 120ms, ease out
- Indeterminate
- A dash fades in across the box
- 120ms, ease out
- Keyboard focus
- A focus ring appears around the box
- none, at once
- Disabled
- The box and its label dim
- none, at once
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The box paints in its checked or empty state | none |
| Check | The fill takes the accent colour and the tick scales in from 90% while fading in | 120ms, ease out |
| Uncheck | The fill and the tick fade back out | 120ms, ease out |
| Indeterminate | A dash fades in across the box | 120ms, ease out |
| Keyboard focus | A focus ring appears around the box | none, at once |
| Disabled | The box and its label dim | none, at once |
Works with
When to use
When to use
- Independent yes or no choices, and lists with select all.
When not to use
- A setting that applies right away: use Switch.
- Exactly one of several options: use Radio Group.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Checkbox to my app and wire it to my own data.
- I need independent yes or no choices, and lists with select all. Set that up with the Knowns UI Checkbox.
- Which Checkbox props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "checkbox" }) and search_docs({ query: "checkbox" }).