Redpanda UIRedpanda UI

Checkbox

A control that allows the user to toggle between checked and not checked.

Made by imskyleen

Installation

Loading component...

Usage

The Checkbox component provides a visually appealing checkbox with smooth animations and comprehensive accessibility support.

import { Checkbox } from "@/components/redpanda-ui/checkbox"

// Basic checkbox
<Checkbox id="terms" />

// Controlled checkbox
const [checked, setChecked] = useState(false)
<Checkbox
  id="newsletter"
  checked={checked}
  onCheckedChange={setChecked}
/>

// With label
<div className="flex items-center space-x-2">
  <Checkbox id="terms" />
  <label htmlFor="terms" className="text-sm font-medium">
    Accept terms and conditions
  </label>
</div>

// Disabled checkbox
<Checkbox id="disabled" disabled />

// With indeterminate state
<Checkbox id="indeterminate" checked="indeterminate" />

When to use

Use this decision tree to determine when to use the Checkbox component:

Use Checkbox when:

  • Users need to select multiple options from a list
  • Confirming agreement (terms, privacy policy)
  • Enabling/disabling individual features or settings
  • Creating multi-select forms
  • Building data tables with row selection
  • Collecting binary preferences (yes/no, on/off)

Don't use Checkbox for:

  • Single choice from multiple options (use Radio Group)
  • Immediate toggle actions (use Switch)
  • Navigation or triggering actions (use Button)
  • Complex multi-step selections (use Multi-Select)

Anatomy

The Checkbox component combines Base UI primitives with Motion animations:

Checkbox Component Structure:
┌─────────────────────────────────────────────────────┐
│ <CheckboxPrimitive.Root> (Base UI primitive)       │
│ ┌─────────────────────────────────────────────────┐ │
│ │ <motion.button> (Interactive element)           │ │
│ │                                                 │ │
│ │ Styles Applied:                                 │ │
│ │ • Size (20x20px)                                │ │
│ │ • Border (2px, changes on state)                │ │
│ │ • Background (transparent → filled)             │ │
│ │ • Focus ring (for accessibility)                │ │
│ │ • Motion effects (scale on hover/tap)           │ │
│ │                                                 │ │
│ │ ┌─────────────────────────────────────────────┐ │ │
│ │ │ <CheckboxPrimitive.Indicator>               │ │ │
│ │ │ ┌─────────────────────────────────────────┐ │ │ │
│ │ │ │ <motion.svg> (Checkmark icon)           │ │ │ │
│ │ │ │                                         │ │ │ │
│ │ │ │ ┌─────────────────────────────────────┐ │ │ │ │
│ │ │ │ │ <motion.path> (Animated path)       │ │ │ │ │
│ │ │ │ │                                     │ │ │ │ │
│ │ │ │ │ Animation States:                   │ │ │ │ │
│ │ │ │ │ • unchecked: pathLength=0, opacity=0│ │ │ │ │
│ │ │ │ │ • checked: pathLength=1, opacity=1  │ │ │ │ │
│ │ │ │ │ • Duration: 0.2s with 0.2s delay   │ │ │ │ │
│ │ │ │ └─────────────────────────────────────┘ │ │ │ │
│ │ │ └─────────────────────────────────────────┘ │ │ │
│ │ └─────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘

State Management:
• Controlled: Uses checked prop with onCheckedChange
• Uncontrolled: Uses defaultChecked prop
• Internal state: Tracks check state for animations
• Supports indeterminate state for partial selections

Accessibility Features:
• Keyboard navigation (Space to toggle)
• Focus management with visible focus ring
• Screen reader support via Base UI primitives
• ARIA attributes automatically applied
• Label association through id/htmlFor

Animation System:
• Motion library integration for smooth interactions
• Scale animations on hover (1.05x) and tap (0.95x)
• Checkmark draws in with pathLength animation
• 500ms color transition for state changes
• Staggered timing: background first, then checkmark

Motion Props Support:
• All HTMLMotionProps<'button'> supported
• Custom animation overrides via motionProps
• Gesture recognition for enhanced interactions

Props

Keyboard interactions

KeyAction
Tab to the checkboxFocus lands on the checkbox.
SpaceToggles between checked / unchecked. Cycles through indeterminate when indeterminate is in use.
EnterSubmits the surrounding form — does not toggle the checkbox.

Accessibility

  • Renders as a real <button role="checkbox"> with aria-checked="true" | "false" | "mixed". The compat layer also sets data-state="checked" | "unchecked" | "indeterminate" so existing Tailwind selectors keep working.
  • Always pair with a visible <Label htmlFor>; if the checkbox is inside a <Field> the label wiring is automatic.
  • Use indeterminate visually only (e.g. parent/child tree selection) — the checkbox still flips to checked on next toggle; don't try to make indeterminate a persistent form value.
  • Group related checkboxes inside a <fieldset> with a <legend> so screen readers announce the group context.

Animate UI Props

Checkbox

Prop

Type

Examples

Default

Loading component...

Days of the week (Maintenance window)

Loading component...

Indeterminate

Loading component...

Parent / select all

Loading component...

Nested hierarchy

Loading component...

Error state

Loading component...

Helper text

Loading component...

Grouped

Loading component...

Form

Loading component...

Credits

Recent changes

  • patchv1.2.0Pin shipped dependency floors to the version we develop against. Registry items now declare ranges like `^5.1.9` (the actual installed version) instead of collapsing to `^5.0.0`, so consumers start on the known-tested b…#133
  • minorv1.1.0Theme docs refresh, readability pass on semantic foregrounds, and consumer-facing Base UI regression fixes.#121
  • minorv1.0.0Post-Base-UI polish. Public API unchanged.#116
  • majorv1.0.0Migrate every Radix-based primitive to `@base-ui/react@^1.4.0` (Base UI).#114
  • patchv0.3.1**Accordion** - `AccordionTrigger` now shows `cursor-pointer` on hover.#112
See full history →
Built by malinskibeniamin. The source code is available on GitHub.

On this page