Overview
Reference usage
Single boolean toggle for opt-in selections within forms or settings.
Usage
Callback order
Three callbacks can observe a toggle, and they fire in this order with different values: onchange fires first, carrying the browser's raw, pre-veto checked value straight from the native change event; onValueChangeRequest runs next and can veto or rewrite the proposed value; onValueChange fires last with the committed value, after any veto has applied. A handler that reads event.target.checked inside onchange sees what the user actually clicked, not the post-veto result — use onValueChange when you need the value Cinder actually committed.
Hit area
The box is drawn 18px, but the row around it is the hit area: at least 24px square, and at least 44px square under a coarse pointer (any-pointer: coarse), the targets of WCAG 2.5.8 and 2.5.5. The padding that makes it is taken back with negative margins, so the row takes exactly the box in layout and a list of checkboxes keeps its rhythm. A press on the padding is forwarded to the input, and the input stays the one keyboard and assistive-technology target.
Alignment with the label
The box sits beside the first line of its label, never the middle of a label that wraps: the field aligns its items to the start and offsets the box so its centre meets the centre of that first line. A one-line label looks the same as it did centred. The label takes the rest of the line and wraps inside it, so a long label stays beside its box. A list row that leads with a checkbox follows the same rule: StackedListItem aligns a leading checkbox to the first line of its title.
Task variant
variant="task" draws the round 20px control of a task list. It shares the checked fill (the accent) and the check glyph with the square box, so the checked state is the same accent fill, which a test holds to 3:1 against the surface, and the unchecked ring keeps the control border tier, which the token contrast audit holds to 3:1. The hit area and the first-line alignment are the same as the square box's.
When to use
- Selecting zero or more independent options from a list.
- Representing a parent state that aggregates child selections via indeterminate.
- Flipping a single setting on or off with immediate effect — use toggle instead.
- Picking exactly one option from a small fixed set — use RadioGroup or segmented-control instead.
Examples
Basic checkbox
Unchecked and checked variants with associated labels.
Disabled checkbox
Disabled state for both unchecked and checked checkboxes.
External row label
A control-only checkbox associated with a rich row label.
Indeterminate checkbox
A parent checkbox driven by its children. Indeterminate clears once the user toggles checked.
Checkbox with error
Validation error message surfaces via aria-invalid and aria-describedby.
Props
Name | Type | Default | Description |
|---|---|---|---|
id | text | Unique identifier for label association and ARIA wiring. Optional: when omitted,
a stable id is generated via $props.id() (or inherited from a FormField context),
matching Input/Autocomplete. Provide it when you need a known id to reference. | |
checked bindable | boolean | false | Bound checked state. |
onValueChangeRequest | (next: boolean) => booleanvoid | Intercept a proposed checked state before the bindable value is written. Return a replacement value to transform it. | |
onValueChange | (next: boolean) => void | Notify after the bindable value has been committed. | |
indeterminate bindable | boolean | false | Bound indeterminate state. Mutually exclusive with checked visually. |
label | text | Visible label rendered in a <label> element associated via for. | |
labelVisible | boolean | true | Whether the label is visibly rendered. Set false for an icon-only checkbox, such as a
card's selection box: the label is hidden visually and stays the accessible name.
Inside a FormField that supplies its own label this changes nothing. |
description | text | Helper text displayed below the checkbox; wired via aria-describedby. | |
error | text | Validation error message; sets aria-invalid="true" and aria-describedby. | |
disabled | boolean | Disables the checkbox. | |
mutating | boolean | false | Marks a checkbox that changes something. Inside a stale <StaleRegion> it goes inert:
aria-disabled, still focusable, a press is undone, and the region's reason describes it.
It returns by itself when the region stops being stale. |
variant | 'default' | 'task' | 'default' | Drawing of the control. default is the square 18px box; task is the round 20px control
of a task list, with the same checked fill and check glyph. Either way the hit area is at
least 24px, and at least 44px under a coarse pointer, without changing the drawn size. |
required | boolean | ||
onchange | ChangeEventHandler<HTMLInputElement>undefinednull |