Skip to content

Checkbox

A single yes/no, or one member of a set of them. Base UI's Checkbox with an acrylic tick on top of it.

tsx
import { Checkbox } from 'neba';

<Checkbox label="Remember me" defaultChecked />;

Props

PropTypeDefaultDescription
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Height and type scale
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''primary'Semantic colour role. Arbitrary colour values are not accepted
labelReactNodeThe label, wired to the control by Base UI's Field
descriptionReactNodeHelper text
errorReactNodeError message. Its presence turns the control invalid and re-points the colour family at danger
invalidboolean!!errorForces the invalid state without a message, for when a form library owns validity
checkedbooleanWhether it is ticked. Use with onCheckedChange for a controlled checkbox
defaultCheckedbooleanfalseThe initial state, for an uncontrolled checkbox
onCheckedChange(checked: boolean, details) => voidCalled when the checkbox is ticked or unticked
indeterminatebooleanfalseNeither ticked nor unticked — a parent whose children disagree
requiredbooleanfalseMust be ticked before the form submits
namestringIdentifies the field when a form is submitted
readOnlybooleanfalseShown but not changeable. Keeps its colour and edge, drains the saturation
disabledbooleanfalseUnavailable. Drops the colour family for neutral grey

label, description and error are props rather than children, for the same reason they are on TextField: the arrangement is fixed, and what a caller wants to decide is what goes in each slot. children is not accepted at all — anything a checkbox has to say belongs in one of the three.

Examples

States

An error also turns the checkbox invalid, which re-points the whole colour family at danger — the tick, the focus ring and the message all turn over together.

Mixed

A parent whose children disagree is neither ticked nor unticked. indeterminate is a third appearance, not a third value: the checkbox is still either on or off underneath.

Sizes

Why the tick is not round

The corner radius on a checkbox is ~30% of its box, not the ~45% the control ladder uses. --neba-radius-md is 14px, which on an 18px box is a circle — and a checkbox that is round is a radio button. The intent is the same as everywhere else in the library: a sheet with the corners cut off, never a pill.

Accessibility

  • Renders a real role="checkbox" with a hidden <input> beside it, so it submits with a form.
  • The label is wired to the control by Base UI's Field: clicking the text toggles the box.
  • Without a label, give it an aria-label.
  • indeterminate reports aria-checked="mixed".

Released under the MIT License