oakoss/ui
Components

Checkbox

A control that turns an option on or off.

SourceReact Aria

Installation

npx shadcn@latest add @oakoss/checkbox

Usage

import { Checkbox } from '#/components/ui/inputs/checkbox';

<Checkbox description="Synced with iCloud Drive.">Sync folders</Checkbox>;

Examples

Description and errors

description explains the option, and errorMessage or errors show while the checkbox is invalid. Both sit under the label.

Synced with iCloud Drive.
Accept the terms to continue.

Indeterminate

isIndeterminate shows a minus, for a checkbox that selects a group where only some options are on.

Accessibility

React Aria renders a native checkbox inside a <label>, so the label is the checkbox's name and its click target. Space toggles it.

  • Description and errors: description and the error describe the checkbox, with no ids to wire. The error shows only while it's invalid. Inside a React Aria CheckboxGroup, the group shows the errors, and a checkbox's own errorMessage and errors don't render.
  • Required: the asterisk after a required label is hidden from screen readers, and the checkbox is marked required. Chrome doesn't expose that state for checkboxes, so where it matters, say so in the label or description. Chrome also reports a required checkbox as invalid until it's checked, as it does any native one, so a screen reader may say "invalid" before the user has touched it; validationBehavior="aria" avoids that, but then the checkbox no longer blocks a native form submit.
  • Indeterminate: screen readers announce it as mixed.
  • Target size: the box's hit area grows to 44px. Set targetSize={false} where checkboxes sit closer than that, or neighbors take each other's clicks; the label row stays at least 24px tall.
  • Contrast: the box's border reaches 3:1 against the page, and an invalid box keeps its error border when checked. In Windows High Contrast the box, fill and check take system colors; an invalid box keeps the normal border there, and the error text carries the state.

API

Checkbox

Renders React Aria's CheckboxField, with its label in a CheckboxButton. Children are the label.

Props

Prop

Type

Also accepts React Aria CheckboxField props.

Data attributes

AttributePresent when
data-slotAlways: checkbox-field on the root, checkbox on the label, checkbox-indicator on the box
data-selectedIt's checked
data-indeterminateIt's indeterminate
data-invalidIt's invalid
data-disabledIt's disabled
data-readonlyIt's read-only
data-requiredIt's required
data-hoveredOn the label, while a pointer hovers it
data-pressedOn the label, while it's pressed
data-focus-visibleOn the label, while it has keyboard focus