Checkbox

Alpha

An accessible checkbox with support for indeterminate state, labels, and CSS variable customization.

Import

import { Checkbox } from "@compa11y/react";

Usage

Example.tsx
import { useState } from "react";
import { Checkbox } from "@compa11y/react";

function Example() {
  const [checked, setChecked] = useState(false);

  return (
    <Checkbox
      checked={checked}
      onCheckedChange={setChecked}
    >
      Accept terms and conditions
    </Checkbox>
  );
}

Features

  • Checked, unchecked, and indeterminate states
  • Accessible label association
  • Custom check icon
  • CSS variable theming
  • Keyboard activation with Space

Props

Checkbox component props
PropTypeDefaultDescription
checkedboolean | 'indeterminate'falseControlled checked state
onCheckedChange(checked: boolean) => void-Called when checked state changes
disabledbooleanfalseDisables the checkbox
childrenReactNode-Label text

Keyboard Interactions

Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
Keyboard shortcuts for Checkbox
KeyAction
SpaceToggles the checkbox

CSS Customization

Override these CSS custom properties to customize the appearance.

CSS custom properties for Checkbox
VariableDescriptionDefault
--compa11y-checkbox-sizeCheckbox dimensions1.25rem
--compa11y-checkbox-radiusBorder radius4px
--compa11y-checkbox-checked-bgChecked state background#0d9488