Skip to main content

Module checkbox

Module checkbox 

Source
Expand description

Checkbox — a two-state or tristate checkbox with an optional label.

Checkbox renders a square (or rounded-square / circle) toggle box alongside an optional label and caption. Two modes are supported:

  • Two-state (Checkbox::new): toggles a Signal<bool> between true (checked) and false (unchecked) on click or Space.
  • Tristate (Checkbox::tristate): cycles a Signal<CheckState> between Checked and Unchecked on user interaction; the Indeterminate state is set only by external sources such as TreeCheckedModel aggregation — clicking from Indeterminate goes to Checked, not a further third state.

Chrome (box shape, fill, focus ring) is driven by the active CheckboxStyle; three visual variants are available via [CheckboxVariant].

§Label styling

The label is Body / Primary and the caption Small / Secondary by default. Checkbox::label_style / Checkbox::label_color and Checkbox::caption_style / Checkbox::caption_color override them. A theme role colour still dims when the checkbox is disabled; a literal Color stays as given.

§Touch and pen

The pressed state comes from the framework press (docs/touch-and-pen.md §7.1) rather than from this widget: sliding off abandons it, sliding back on restores it, and a pan claimant winning the press clears it with no release. Before the controls sweep is_pressed could only ever be set by a keyboard Space, so a mouse-down showed no pressed chrome at all — themes that paint one (IntUI’s checked box, Material 3’s state layer) now get it from every pointer.

The 24 dp MinSize around the 19 dp glyph already meets the WCAG 2.2 SC 2.5.8 floor at Compact and follows the density ladder above it, so no hit-widening mechanism is involved.

§Accessibility

Announces as Role::CheckBox. A label is required in debug builds unless .labelled_externally() is set (for embedding inside a composite row that owns the AT name). Keyboard: Space toggles; lone-KeyUp guard prevents spurious toggle when focus is restored after a shortcut.

let checked = Signal::new(false);
let _cb = Checkbox::new(checked)
    .label(lit!("Accept terms and conditions"));

Structs§

Checkbox
A checkbox that toggles a Signal<bool> or cycles a Signal<CheckState>.