Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ToggleButton

A button-style input that toggles between checked and unchecked states.

When To Use It

Use ToggleButton when you want button visuals with persistent on/off state, such as bold/italic toolbar actions or feature toggles.

Constructing a ToggleButton

ToggleButton binds to a bool and accepts custom button content:

let enabled = Signal::new(false);

ToggleButton::new(cx, enabled, |cx| Label::new(cx, "Snap"))
	.on_toggle(|cx| cx.emit(AppEvent::ToggleSnap));

Icon content works the same way:

ToggleButton::new(cx, is_bold, |cx| Svg::new(cx, ICON_BOLD))
	.name("Bold")
	.on_toggle(|cx| cx.emit(AppEvent::ToggleBold));

ToggleButton Modifiers

ModifierTypeDescriptionDefault
on_toggleFn(&mut EventContext)Called when the button is activated/toggled.-

Components and Styling

SelectorDescription
toggle-buttonRoot element.
toggle-button:checkedChecked/active state.
toggle-button:disabledDisabled state.

Because content is custom, child selectors depend on what you place inside (label, svg, stacks, etc.).

Accessibility

ToggleButton uses role Button, is checkable, and reports checked state to assistive tech.

Keyboard interaction:

KeyAction
Space / EnterActivates/toggles the button when focused.