Checkbox

Checkbox allows users to select one or more items from a set.

About once a month. Unsubscribe any time.
tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';

<Checkbox
  label="Email me about product updates"
  description="About once a month. Unsubscribe any time."
  defaultChecked
/>

Installation

pnpm dlx wideset add checkbox

Copies the component and any Wideset components it uses into your project.

Examples

Variants

Primary is the default for every ordinary choice. Danger is for a choice with consequences the user must not tick by accident, such as deleting data along with an account. The colour is only a hint: the label has to say what happens.

tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';

export default function CheckboxVariants() {
  return (
    <div className="gap-ws-12 flex flex-col">
      <Checkbox variant="primary" label="Keep me signed in" defaultChecked />
      <Checkbox variant="danger" label="Also delete all my projects" defaultChecked />
    </div>
  );
}

Sizes

Large is the default and suits forms and settings. Small is for dense places such as table rows and filter panels. Keep one size within a group.

tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';

export default function CheckboxSizes() {
  return (
    <div className="gap-ws-12 flex flex-col">
      {(['lg', 'sm'] as const).map((size) => (
        <Checkbox key={size} size={size} label="Email me about product updates" defaultChecked />
      ))}
    </div>
  );
}

Labels

A checkbox always has a visible label, except where a column header or a row already says what it selects; then it needs an aria-label. The description is not part of the name: screen readers read it after the label, as the description.

tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';

export default function CheckboxLabels() {
  return (
    <div className="gap-ws-11 flex flex-wrap items-start justify-center">
      <Checkbox aria-label="Select row" />
      <Checkbox label="Email me about product updates" />
      <Checkbox
        label="Email me about product updates"
        description="About once a month. Unsubscribe any time."
      />
    </div>
  );
}

States

Indeterminate is for a parent checkbox whose children are only partly selected, such as "Select all" over a table; clicking it checks everything. Screen readers announce it as "mixed". A disabled checkbox leaves the tab order and keeps its value, so use it only when the option is unavailable for a reason the user can see.

tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';

const states = [
  { label: 'Unchecked', checked: false, disabled: false },
  { label: 'Checked', checked: true, disabled: false },
  { label: 'Indeterminate', checked: 'indeterminate', disabled: false },
  { label: 'Disabled', checked: false, disabled: true },
  { label: 'Disabled, checked', checked: true, disabled: true },
] as const;

export default function CheckboxStates() {
  return (
    <div className="gap-x-ws-11 gap-y-ws-7 grid grid-cols-[8rem_auto] items-center">
      {states.map((state) => (
        <div key={state.label} className="contents">
          <span className="typography-caption-md text-ws-static-subtle">{state.label}</span>
          <Checkbox
            label="Select all invoices"
            defaultChecked={state.checked}
            disabled={state.disabled}
          />
        </div>
      ))}
    </div>
  );
}

API reference

NameDescriptionDefault
children

Composed label and description. Use instead of the shorthand label and description.

ReactNode
—
defaultMotion

Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`.

boolean
true
description

Supporting text for the shorthand label. Unavailable with composed children.

string
—
label

Shorthand label, mutually exclusive with composed children.

string
—
size
'sm''lg'
'lg'
variant
'primary''danger'
'primary'

Accessibility

  • Always a visible label, except where a column header or row already names it: then aria-label.
  • The description, shorthand or Checkbox.Description, sits outside the label and is linked to the checkbox with aria-describedby for you. Your own aria-describedby is kept alongside it.
  • Indeterminate is announced as “mixed”.
  • Inside FormField, the field links its helper or error text to the checkbox and sets aria-invalid on error; pass id and the field’s htmlFor.
About once a month. Unsubscribe any time.
tsx
import { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';

<Checkbox
  label="Email me about product updates"
  description="About once a month. Unsubscribe any time."
  defaultChecked
/>

Appearance

Variant
Size

Content

Label
Description

State

Checked
Disabled