Checkbox

Selects options that take effect when a form is submitted.

import { Checkbox } from "@usefragments/ui";Source

Preview

<StatefulCheckbox label="Accept terms and conditions" />

Usage

Use when

  • Choices that apply only once the form is submitted
  • Picking several items from a list
  • Accepting terms
  • Filter and preference lists

Avoid when

  • Settings that apply instantly (use Switch)
  • One choice from a few (use RadioGroup)
  • Many options (use Select)

Implementation notes

  • Always show a label
  • Add helperText when the consequence is not obvious
  • Keep related boxes together
  • Use indeterminate for a parent whose children are partly checked
  • Pair invalid with an errorMessage; the danger edge alone is colour only

Installation

pnpm add @usefragments/ui

The npm package stays managed by your package manager. Import styles once from @usefragments/ui/styles. See the installation guide for framework and theme setup.

Examples

With Helper Text

Second line spells out what opting in does.

<StatefulCheckbox
  label="Email notifications"
  helperText="Receive email updates about your account activity"
/>

Checked

Starts on.

<StatefulCheckbox defaultChecked label="Subscribe to newsletter" />

Indeterminate

A dash on the parent means only some children are on.

<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
  <Checkbox indeterminate label="Select all" />
  <div style={{ marginLeft: '24px', display: 'flex', flexDirection: 'column', gap: '8px' }}>
    <StatefulCheckbox defaultChecked label="Option 1" />
    <StatefulCheckbox label="Option 2" />
    <StatefulCheckbox defaultChecked label="Option 3" />

Disabled

Locked in both positions, on and off.

<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
  <Checkbox disabled label="Disabled unchecked" />
  <Checkbox disabled checked label="Disabled checked" />
</div>

Invalid

A danger edge on the box and a message with an icon under the label.

<Checkbox
  label="I accept the terms"
  invalid
  errorMessage="Accept the terms to continue."
/>

Outline Card

The whole card picks; checked turns its hairline into the selection ring.

<StatefulCheckbox
  variant="outline"
  label="Weekly summary"
  helperText="One email on Monday morning."
/>

API reference

Component props
Prop
Type
Default
Description
aria-describedbystring | undefinedNot setAccessible described-by relationship
aria-labelstring | undefinedNot setAccessible label when there is no visible label
aria-labelledbystring | undefinedNot setAccessible labelled-by relationship when there is no visible label
checkedboolean | undefinedNot setControlled checked state
defaultCheckedboolean | undefinedNot setDefault checked state (uncontrolled)
disabledboolean | undefinedfalseDisable the checkbox
errorMessageReact.ReactNodeNot setMessage shown with a warning icon under the label while invalid; wired to aria-describedby
formstring | undefinedNot setID of the form that owns the hidden input
helperTextstring | undefinedNot setHelper text shown below the label
idstring | undefinedNot setID for the checkbox input
indeterminateboolean | undefinedfalseIndeterminate state (partial selection)
inputRefReact.Ref<HTMLInputElement> | undefinedNot setRef to the hidden input element
invalidboolean | undefinedfalseThe value fails validation: danger edge on the box and errorMessage under the label
labelstring | undefinedNot setLabel text
namestring | undefinedNot setName attribute for form submission
onCheckedChange((checked: boolean) => void) | undefinedNot setCalled with the next checked state when the user toggles the checkbox
parentboolean | undefinedNot setWhether this checkbox controls child checkboxes in a checkbox group
readOnlyboolean | undefinedfalseThe checkbox cannot be changed; band fill and a dashed edge
requiredboolean | undefinedfalseWhether the checkbox is required
uncheckedValuestring | undefinedNot setValue submitted when unchecked
valuestring | undefinedNot setValue attribute for form submission
variant"outline" | undefinedoutlineNot setChrome. Omit for the inline checkbox beside its label; 'outline' renders a full-width choice card (surface, hairline, surface radius) whose hairline turns into the selection ring when checked.

Accessibility

  • Label is tied to the box
  • Space toggles it
  • Focus ring stays visible
  • Indeterminate is announced as mixed
  • The error message is wired to aria-describedby and carries an icon and words
  • SwitchalternativeUse Switch for immediate-effect settings
  • InputsiblingCheckbox handles boolean; Input handles text

Next steps