Checkbox
An accessible checkbox component with label, description, indeterminate state, and group support.
Overview
The Checkbox component is an accessible checkbox built on Radix UI. It supports labels, descriptions, indeterminate state, error styling, two sizes, and group composition with vertical or horizontal orientation.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add checkboxpnpm dlx @work-rjkashyap/unified-ui add checkboxnpx @work-rjkashyap/unified-ui add checkboxbunx @work-rjkashyap/unified-ui add checkboxIf you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.
Or install the full package
Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.
npm install @work-rjkashyap/unified-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
import {
Checkbox,
CheckboxGroup,
} from "@work-rjkashyap/unified-ui";Examples
Basic Usage
Sizes
With Description
Indeterminate State
Disabled State
Error State
You must accept the terms to continue.
Checkbox Group — Vertical
Checkbox Group — Horizontal
Checkbox Group — With Description
Combined Features
Required to create an account.
Props
Checkbox
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | "indeterminate" | — | Controlled checked state. |
defaultChecked | boolean | false | Initial checked state (uncontrolled). |
onCheckedChange | (checked: boolean | "indeterminate") => void | — | Callback when checked state changes. |
size | "sm" | "md" | "md" | Size of the checkbox. |
label | ReactNode | — | Clickable label text. |
description | ReactNode | — | Description text below the label. |
value | string | — | Value used when inside a CheckboxGroup. |
error | boolean | false | Whether to show error styling. |
disabled | boolean | false | Whether the checkbox is disabled. |
className | string | — | Additional CSS classes. |
CheckboxGroup
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | Group label displayed above the checkboxes. |
description | ReactNode | — | Description text below the group label. |
orientation | "vertical" | "horizontal" | "vertical" | Layout direction of the checkboxes. |
size | "sm" | "md" | "md" | Size applied to all child checkboxes. |
error | boolean | false | Whether to show error styling on all children. |
disabled | boolean | false | Whether all children are disabled. |
className | string | — | Additional CSS classes. |
Accessibility
Built on @radix-ui/react-checkbox which provides full keyboard and screen reader support out of the box.
- Keyboard —
Spacetoggles the checkbox.Tabmoves focus between checkboxes. - Focus ring — Visible on keyboard navigation via
focus-visible. - Label — Clicking the label text toggles the checkbox (integrated
<label>element). - Indeterminate — Properly exposed via
aria-checked="mixed". - Group —
CheckboxGroupusesrole="group"witharia-labelledbyfor the group label. - Disabled — Sets both the
disabledattribute andaria-disabled. - Error — The
errorprop applies visual styling. Pair witharia-describedbyand an error message element for screen reader support.
Design Tokens
| Token | Usage |
|---|---|
--primary | Checked state background |
--primary-foreground | Checkmark icon color |
--danger | Error state border |
--radius-sm | Checkbox border radius |
--duration-fast | Transition speed |