pub fn checkbox() -> CheckboxBuilderExpand description
§checkbox
Renders an interactive checkbox with an animated checkmark.
§Usage
Capture a boolean choice or represent partial selection for a group of choices.
§Parameters
modifier— modifier chain applied to the checkbox subtree.focus_requester— optional handle targeting the checkbox for focus requests.on_toggle— toggle callback invoked with the new checked state.checked— externally controlled checked state; omit to use the controller.indeterminate— partial selection, taking precedence overchecked; activation clears this state and requeststruethroughon_toggle.presentation_state— optional visual interaction; live input and disabled state take precedence.is_error— validation error state; publishes invalid semantics and uses error colors unless explicitly overridden. Supply validation details withaccessibility_description. Disabled colors take precedence.size— optional checkbox glyph size.color— optional unchecked outline color.checked_color— optional checked container color.checkmark_color— optional checkmark icon color.checkmark_stroke_width— optional stroke width in physical pixels; defaults to 2dp rounded down to a whole pixel.shape— optional outer checkbox shape.disabled— whether the checkbox is disabled.disabled_color— optional disabled border/container color.disabled_checkmark_color— optional disabled checkmark color.accessibility_label— optional accessibility label.accessibility_description— optional accessibility description.controller— optional external checkbox controller.
§Examples
use tessera_components::checkbox::{CheckboxController, checkbox};
use tessera_ui::{remember, tessera};
#[tessera]
fn checkbox_demo() {
let controller = remember(|| {
let mut controller = CheckboxController::new(false);
controller.set_indeterminate(true);
assert!(controller.is_indeterminate());
controller.toggle();
assert!(controller.is_checked());
assert!(!controller.is_indeterminate());
controller
});
checkbox().controller(controller);
let choices = remember(|| [true, false]);
let all = choices.with(|values| values.iter().all(|value| *value));
let some = choices.with(|values| values.iter().any(|value| *value));
checkbox()
.checked(all)
.indeterminate(some && !all)
.is_error(!some)
.accessibility_description("Choose at least one option")
.on_toggle(move |value| choices.set([value; 2]));
}