Checkbox
Boolean selection control for settings, forms, filters, consent, and multi-select product flows in PyColors UI.
Boolean choices for forms and product settingsLink to section
The Checkbox component lets users select one or more options from a list, confirm a setting, or opt into a specific condition.
Use it for:
- settings toggles that can be selected independently
- multi-select filters
- terms, consent, and confirmation fields
- grouped preferences
- checklist-style product flows
- optional form choices
Checkbox is built on Radix Checkbox and styled with PyColors semantic tokens such as border-input, bg-background, text-foreground, and ring-ring.
Core idea
Checkbox is for explicit selection. Use it when each option can be independently checked or unchecked.
ImportLink to section
import { Checkbox } from "@pycolors/ui";Basic usageLink to section
Use a Checkbox with a label when the user needs to enable or select one option.
Collect product usage data to improve the dashboard experience.
Label rule
Always connect the visible label with the checkbox using htmlFor and id,
unless the label wraps the control directly.
When to use CheckboxLink to section
Use Checkbox when options are independent and the user can select multiple choices.
Settings
Filters
Consent
Checked stateLink to section
Use defaultChecked for uncontrolled checkboxes and checked with onCheckedChange for controlled product state.
This option starts checked and can be changed by the user.
This option starts unchecked.
Controlled checkboxLink to section
Use a controlled Checkbox when the checked value drives application state.
Add auth, billing, and protected route foundations to the setup.
State rule
Radix Checkbox can return true, false, or "indeterminate". Convert the
value intentionally when your app expects a boolean.
Indeterminate stateLink to section
Use the indeterminate state for parent checkboxes when only some child items are selected.
Some features are currently selected.
Disabled stateLink to section
Use disabled checkboxes only when the option cannot currently be changed.
This option is unavailable on the current plan.
This setting is enabled by default and cannot be changed.
Disabled copy
When a disabled option may frustrate users, explain why it is unavailable and what unlocks it.
Form validationLink to section
Use the error prop when a required checkbox is not selected. It renders visible
error copy, sets aria-invalid, and connects the message with both
aria-describedby and aria-errormessage. The error has role="alert", so it
is announced when it appears. Consumer-provided aria-describedby values are
preserved alongside the error message id.
You must accept the terms before continuing.
Required before creating a workspace.
Usage patternsLink to section
Use checkboxes for independent options
Each checkbox should represent one choice that can be selected without forcing a mutually exclusive decision.
Keep labels clear and specific
The label should explain exactly what gets enabled, selected, or confirmed.
Add descriptions for important consequences
Use CheckboxDescription when the choice affects privacy, billing, delivery, visibility, or access.
Handle indeterminate state intentionally
Use "indeterminate" only when representing a mixed group state.
Validate required confirmations
For required consent or terms fields, show a direct error message near the checkbox.
Checkbox vs Switch vs Radio GroupLink to section
| Situation | Use |
|---|---|
| Multiple independent selections | Checkbox |
| Required consent or confirmation | Checkbox |
| Parent selection with mixed children | Checkbox with indeterminate state |
| Immediate on/off setting | Switch |
| One choice from a mutually exclusive group | Radio Group |
| Small menu action list | Dropdown Menu |
Decision rule
Use Checkbox for selection, Switch for immediate enablement, and Radio Group for one exclusive choice.
APILink to section
Components
| Component | Description |
|---|---|
Checkbox | Root checkbox control built on Radix Checkbox |
CheckboxField | Layout helper for checkbox rows |
CheckboxContent | Text stack helper for label and description |
CheckboxLabel | Accessible label helper |
CheckboxDescription | Supporting text helper |
Checkbox props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | "indeterminate" | — | Controlled checked state |
defaultChecked | boolean | "indeterminate" | — | Initial uncontrolled checked state |
onCheckedChange | (checked) => void | — | Called when the checked state changes |
disabled | boolean | false | Disables the checkbox |
required | boolean | false | Marks the checkbox as required |
error | string | — | Renders an announced error and sets the invalid state |
name | string | — | Form field name |
value | string | — | Submitted form value |
className | string | — | Additional Tailwind classes |
Checkbox extends Radix Checkbox Root props.
TypeScript typesLink to section
export interface CheckboxProps extends React.ComponentPropsWithoutRef<
typeof CheckboxPrimitive.Root
> {
error?: string;
}
const Checkbox = React.forwardRef<
React.ComponentRef<typeof CheckboxPrimitive.Root>,
CheckboxProps
>((props, ref) => {
// ...
});AccessibilityLink to section
Checkbox is built on Radix Checkbox primitives.
That means:
- keyboard interaction is handled
- checked and indeterminate states are exposed to assistive technologies
- disabled state is exposed correctly
- focus styling uses PyColors ring tokens
- form usage works through native form semantics
errorrenders visible error copy and wiresaria-invalid,aria-describedby, andaria-errormessage
Guidelines:
- provide a visible label for every checkbox
- connect labels using
htmlForandid - use descriptions for choices with consequences
- do not rely on color alone for validation states
- use the
errorprop for invalid required confirmations - keep checkbox labels short and action-oriented
Accessibility rule
A checkbox needs a clear accessible name. The label should make sense even when read without surrounding context.
Prefer / avoidLink to section
Prefer
- clear labels connected with htmlFor and id
- checkboxes for independent multi-select choices
- descriptions for privacy, billing, or access impact
- indeterminate state for mixed parent selection
- visible validation copy for required confirmations
Avoid
- using checkbox for mutually exclusive choices
- using checkbox as an immediate setting when switch is clearer
- labels that only say “Yes” or “Enable”
- disabled options without explanation
- color-only error communication
Product copy guidelinesLink to section
Checkbox copy should describe the selected outcome, not the UI control.
Send weekly product summary
Receive a short email with usage, billing, and workspace activity.