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
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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
checked | boolean | No | Controlled checked state. | |
defaultChecked | boolean | No | false | Initial checked state for uncontrolled usage (also the value a form reset restores). |
indeterminate | boolean | No | false | Shows the mixed state: the dash glyph and |
onCheckedChange | (checked: boolean) => void | No | Called with the new checked state when it changes (not for no-op updates). | |
disabled | boolean | No | Whether the checkbox is disabled and non-interactive. | |
disabledFocusable | boolean | No | false | 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 |
label | React.ReactNode | No | Label next to the control (any phrasing content, links included, but no other form controls). It names the control through | |
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. |
name | string | No | Form field name. With a name, the checkbox takes part in native form submission: it submits | |
value | string | No | 'on' | Value submitted while checked. |
required | boolean | No | The form must not be submitted while the checkbox is unchecked (native validation). | |
form | string | No | Id of the form the checkbox belongs to, when it is rendered outside that form. | |
onClick | React.MouseEventHandler<HTMLButtonElement> | No | Click handler of the checkbox control (the | |
onFocus | React.FocusEventHandler<HTMLButtonElement> | No | Focus handler of the checkbox control. | |
onBlur | React.FocusEventHandler<HTMLButtonElement> | No | Blur handler of the checkbox control. | |
onKeyDown | React.KeyboardEventHandler<HTMLButtonElement> | No | Keydown handler of the checkbox control. | |
onKeyUp | React.KeyboardEventHandler<HTMLButtonElement> | No | Keyup handler of the checkbox control. | |
ref | React.Ref<HTMLButtonElement> | No | Ref to the focusable | |
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 |
Any other prop is passed to the element it renders (HTMLLabelElement).
Parts
rootindicatorlabel
Stable class names
| Part | Class |
|---|---|
root | wave-checkbox |
indicator | wave-checkbox__indicator |
label | wave-checkbox__label |