Skip to content

Checkbox

Checkbox

A checkbox for a boolean (or mixed) choice, drawn as a role="checkbox" button inside a <label>.

- ref reaches the control; the root <label> receives className, style and data-* (slotProps.root.ref reaches it); the control receives id, aria-label/-labelledby/-describedby/-invalid/-required/-errormessage/ -details/-disabled, tabIndex, autoFocus and the click, focus and key handlers. A consumer onClick runs once per activation, before the toggle; preventDefault() in it cancels the toggle.
- Inside a Field it is named by the Field label (followed by its own label text) and described by the Field message and hint.
- With name (or required) it takes part in native forms like <input type="checkbox">, and a form reset restores defaultChecked.
- label takes rich content (a link to the terms) and renders after the box, or before it with labelPosition="before" (the root carries data-label-position). The box lines up with the first line of a label that wraps or has a second line. children are not rendered (a development warning says so).
- size (medium, large) and shape (square, circular) set the box's dimensions and corners; the root carries data-size and data-shape. Checkbox does not read a surrounding Field's size or a WaveProvider's input defaults.

Examples

Default

export const Default: Story = {};

Checked

export const Checked: Story = {
  args: {
    defaultChecked: true,
  },
};

Indeterminate

export const Indeterminate: Story = {
  args: {
    label: 'Select all',
  },
  render: function SelectAll(args) {
    const fruits = ['Apples', 'Bananas', 'Cherries'];
    const [picked, setPicked] = useState([true, false, false]);
    const all = picked.every(Boolean);
    return (
      <div className="flex flex-col gap-2">
        <Checkbox
          {...args}
          checked={all}
          indeterminate={!all && picked.some(Boolean)}
          onCheckedChange={(next) => {
            setPicked(picked.map(() => next));
            args.onCheckedChange?.(next);
          }}
        />
        <div className="flex flex-col gap-2 ps-6">
          {fruits.map((fruit, i) => (
            <Checkbox
              key={fruit}
              label={fruit}
              checked={picked[i]}
              onCheckedChange={(next) => setPicked(picked.map((v, j) => (j === i ? next : v)))}
            />
          ))}
        </div>
      </div>
    );
  },
};

With Label

export const WithLabel: Story = {
  args: {
    label: 'Subscribe to the newsletter',
  },
};

Disabled

export const Disabled: Story = {
  args: {
    label: 'Disabled option',
    disabled: true,
  },
};

Without Visible Label

export const WithoutVisibleLabel: Story = {
  args: {
    label: undefined,
    'aria-label': 'Select row',
  },
};

In Form

export const InForm: Story = {
  args: {
    name: 'terms',
    value: 'accepted',
    required: true,
  },
  render: (args) => (
    <form className="flex flex-col items-start gap-3" onSubmit={(e) => e.preventDefault()}>
      <Checkbox {...args} />
      <Button type="submit" appearance="primary">
        Submit
      </Button>
    </form>
  ),
};

Rich Label

export const RichLabel: Story = {
  args: {
    label: (
      <>
        I agree to the <Link href="#terms">terms and conditions</Link>
      </>
    ),
  },
};

Label Before

export const LabelBefore: Story = {
  args: {
    label: 'Remember me',
    labelPosition: 'before',
  },
};

Disabled Focusable

Only administrators can share with the organization.

export const DisabledFocusable: Story = {
  args: {
    label: 'Share with the whole organization',
    disabledFocusable: true,
    'aria-describedby': 'share-reason',
  },
  render: (args) => (
    <div className="flex flex-col items-start gap-1">
      <Checkbox {...args} />
      <p id="share-reason" className="text-wave-caption-1 text-wave-muted-foreground">
        Only administrators can share with the organization.
      </p>
    </div>
  ),
};

Sizes And Shapes

export const SizesAndShapes: Story = {
  render: (args) => (
    <div className="grid grid-cols-2 gap-3">
      {(['medium', 'large'] as const).flatMap((size) =>
        (['square', 'circular'] as const).map((shape) => (
          <Checkbox
            {...args}
            key={`${size}-${shape}`}
            size={size}
            shape={shape}
            defaultChecked={shape === 'square'}
            label={`${size} ${shape}`}
          />
        )),
      )}
    </div>
  ),
};

Props

NameTypeRequiredDefaultDescription
checkedbooleanNo

Controlled checked state.

defaultCheckedbooleanNofalse

Initial checked state for uncontrolled usage (also the value a form reset restores).

indeterminatebooleanNofalse

Shows the mixed state: the dash glyph and aria-checked="mixed", whatever checked is. A click still toggles checked and calls onCheckedChange, but the checkbox keeps showing and announcing "mixed" until you clear indeterminate. For a tri-state "select all", derive checked and indeterminate from the items and set every item in onCheckedChange.

onCheckedChange(checked: boolean) => voidNo

Called with the new checked state when it changes (not for no-op updates).

disabledbooleanNo

Whether the checkbox is disabled and non-interactive.

disabledFocusablebooleanNofalse

Marks the checkbox unavailable but keeps it focusable and in the tab order: for a disabled checkbox that needs a Tooltip, or one in a toolbar. Renders aria-disabled="true", data-disabled and data-disabled-focusable on the checkbox instead of the native disabled attribute. The checkbox cannot be toggled and is not submitted with its form; your onClick is not called, and a click on the checkbox (or Space and Enter) does not reach ancestor click handlers, as for a natively disabled control. Wins over disabled when both are set. In a roving container (a Toolbar) it stays in the arrow-key order.

labelReact.ReactNodeNo

Label next to the control (any phrasing content, links included, but no other form controls). It names the control through aria-labelledby, after a consumer or Field aria-labelledby; a consumer aria-label names it instead. Clicking its text toggles the control; clicking a link inside it follows the link. children are not rendered: pass the label here.

labelPosition'before' | 'after'No'after'

Where the label renders: after the control (default) or before it. The DOM order follows the visual order.

size'medium' | 'large'No'medium'

Size of the box: an 18px box (the 0.7 look) or a 22px box with a bigger glyph. Unlike the text controls and pickers, Checkbox does not read a surrounding Field's size or a WaveProvider's input defaults: this prop is the only source of its size.

shape'circular' | 'square'No'square'

Shape of the box: square corners (the 0.7 look) or a circular, round box.

namestringNo

Form field name. With a name, the checkbox takes part in native form submission: it submits name=value while checked.

valuestringNo'on'

Value submitted while checked.

requiredbooleanNo

The form must not be submitted while the checkbox is unchecked (native validation).

formstringNo

Id of the form the checkbox belongs to, when it is rendered outside that form.

onClickReact.MouseEventHandler<HTMLButtonElement>No

Click handler of the checkbox control (the role="checkbox" button).

onFocusReact.FocusEventHandler<HTMLButtonElement>No

Focus handler of the checkbox control.

onBlurReact.FocusEventHandler<HTMLButtonElement>No

Blur handler of the checkbox control.

onKeyDownReact.KeyboardEventHandler<HTMLButtonElement>No

Keydown handler of the checkbox control.

onKeyUpReact.KeyboardEventHandler<HTMLButtonElement>No

Keyup handler of the checkbox control.

refReact.Ref<HTMLButtonElement>No

Ref to the focusable role="checkbox" button (Fluent UI's ref, on its primary element). The root <label> is slotProps.root.ref.

slotProps{ root?: SlotPart<'label'>; indicator?: SlotPart<'button'>; label?: SlotPart<'span'> }No

Props for the elements the Checkbox draws, by part, merged into each part's own (Fluent UI's root, indicator and label slot props): your classes after the part's (yours win a conflict), your styles over its styles, your handlers before its handlers (preventDefault() in yours skips the Checkbox's handling of the event, its own on… prop included), your ref beside its ref, and your ids added to its aria-labelledby and aria-describedby. Every attribute the Checkbox sets on a part is locked and keeps the Checkbox's value (set it through the Checkbox's own props); you add the attributes it does not set. A part takes no children.

Any other prop is passed to the element it renders (HTMLLabelElement).

Parts

  • root
  • indicator
  • label

Stable class names

PartClass
rootwave-checkbox
indicatorwave-checkbox__indicator
labelwave-checkbox__label