Skip to main content

Checkbox

Checkbox is the standard boolean toggle for independent choices.

Use it when the user is deciding whether something is included, enabled, acknowledged, or selected among many independent items. A checkbox is different from a Radio: radios mean "pick exactly one", while checkboxes mean "each option stands on its own".

Example

use fission::core::{Handler, ReducerContext};
use fission::core::ui::Checkbox;

#[fission_action]
struct ToggleNewsletter;

fn on_toggle(state: &mut SettingsState, _action: ToggleNewsletter, _ctx: &mut ReducerContext<SettingsState>) {
state.receive_newsletter = !state.receive_newsletter;
}

let node = Checkbox {
checked: view.state.receive_newsletter,
label: Some("Receive product updates".into()),
on_toggle: Some(ctx.bind(
ToggleNewsletter,
reduce_with!(on_toggle),
)),
..Default::default()
}
.into_node();

The checkbox does not flip itself. It emits an action, the reducer changes AppState, and the next build reads the new checked value from View.

Field table

FieldTypeMeaningNotes / default behavior
idOption<NodeId>Stable node identity.Defaults to None.
checkedboolWhether the checkbox is currently selected.Defaults to false.
on_toggleOption<ActionEnvelope>Action dispatched when the user toggles the checkbox.Defaults to None.
labelOption<String>Visible text shown next to the indicator.Defaults to None, but most real checkboxes should have a label.

Interaction and accessibility behavior

Checkbox lowers a semantic checkbox role with the current checked state, so assistive technology can report it correctly and automated tests can find it by role. The label text is also used as the semantic label when present.

Because the control is controlled by state, it is easy to test. Given a known checked value, the same build always produces the same visual and semantic result.

Specific advice

Prefer a checkbox when the choice can stay pending until a later submit. If the control means an immediate app setting that turns behavior on or off right away, a Switch often reads more naturally.

Switch, Radio, FormControl, and Button.