Skip to main content

checkbox

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

Philosophy

Checkboxes are deceptively complex. A simple checked/unchecked state becomes indeterminate for parent/child relationships, needs accessible labels, and must work in both controlled and uncontrolled modes. We handle all of this with native checkbox semantics and custom SVG indicators, so the visual design is yours while the behavior is correct.

How It's Built

Loading diagram...

Installation


npx @gentleduck/cli add checkbox

npx @gentleduck/cli add checkbox

Usage

import { Checkbox } from "@/components/ui/checkbox"
import { Checkbox } from "@/components/ui/checkbox"
<Checkbox />
<Checkbox />

Examples

Basic uncontrolled checkbox

Controlled checkbox

Checkbox with label

Indeterminate state

Checkbox group

Custom indicator icons

Form

Component Composition

Loading diagram...

API Reference

Checkbox

PropTypeDefaultDescription
indicatorReact.ReactElement--Custom SVG or icon for unchecked state indicator
checkedIndicatorReact.ReactElement--Custom SVG or icon for checked state indicator
checkedboolean | 'indeterminate'--Controlled checked state
defaultCheckedboolean | 'indeterminate'falseInitial checked state if uncontrolled
onCheckedChange(checked: boolean | 'indeterminate') => void--Callback fired when checked state changes
dir'ltr' | 'rtl'--Text direction override. Resolved via useDirection (dir prop -> DirectionProvider -> 'ltr').
classNamestring--Additional CSS classes applied to the checkbox input
styleReact.CSSProperties--Inline styles merged with internal indicator styles
refReact.Ref<HTMLInputElement>--Ref forwarded to the native checkbox input
...propsOmit<React.HTMLProps<HTMLInputElement>, 'checked' | 'onChange' | 'defaultChecked'>--Additional props to spread to the input element

CheckboxWithLabel

PropTypeDefaultDescription
idstring(required)HTML id attribute to link checkbox and label
_checkboxReact.ComponentPropsWithoutRef<typeof Checkbox>(required)Props passed to the internal Checkbox component
_labelReact.ComponentPropsWithoutRef<typeof Label>(required)Props passed to the internal Label component
classNamestring--Additional CSS classes applied to the wrapping div
refReact.Ref<HTMLDivElement>--Ref forwarded to the wrapping div
...propsReact.HTMLProps<HTMLDivElement>--Additional props to spread to the content div

CheckboxGroup

PropTypeDefaultDescription
subtasksCheckboxGroupSubtasks[](required)Array of subtasks to render as individual checkboxes with labels
subtasks_default_valuesCheckboxWithLabelProps--Default props applied to each checkbox and label in the group
classNamestring--Additional CSS classes applied to the wrapping div
refReact.Ref<HTMLDivElement>--Ref forwarded to the wrapping div
...propsReact.HTMLProps<HTMLDivElement>--Additional props to spread to the content div

CheckboxGroupSubtasks

type CheckboxGroupSubtasks = {
  id: string
  title: string
  checked?: boolean | 'indeterminate'
}
type CheckboxGroupSubtasks = {
  id: string
  title: string
  checked?: boolean | 'indeterminate'
}

RTL Support

Direction is resolved through the shared primitives direction module. Use a local dir="rtl" override when the component exposes it, or set DirectionProvider at app/root level for global RTL/LTR behavior.

See also

  • Radio Group — Single selection from a set of options
  • Switch — Toggle between on and off states