Skip to content

Checkbox

A single item that can be ticked. Use it for a boolean submitted with a form, or for a list where several items can be chosen at once.

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
classNamesNebaSlots<'label' | 'control' | 'description' | 'error' | 'indicator'>Class names for the parts behind the root. The root itself is className, so there is no root key

label, description and error are props rather than children; children is not accepted.

For a setting that takes effect immediately, use Switch. A Checkbox is a value submitted alongside a Save button.

Examples

checked and onCheckedChange

checked with onCheckedChange makes it controlled; defaultChecked makes it uncontrolled.

disabled · readOnly · error

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

indeterminate

A third appearance for a parent checkbox whose children disagree. The value underneath is still on or off; indeterminate only affects what is drawn.

size

classNames

className lands on the field wrapper, not on the tick. The tick and the mark inside it are reached through classNames.

tsx
<Checkbox label="I agree" classNames={{ control: 'rounded-full', label: 'font-medium' }} />

The slots are label, control, indicator, description and error. control is the tick itself (the bordered box that fills when checked), and indicator is the mark inside it. See prop conventions for how a class name you pass resolves against the component's own.

Accessibility

  • Renders role="checkbox" with a hidden <input> beside it, so giving it a name submits it with a form.
  • The label is wired to the control, so clicking the text toggles the box.
  • Without a label, give it an aria-label.
  • indeterminate reports aria-checked="mixed".

Released under the MIT License