-
Notifications
You must be signed in to change notification settings - Fork 9
Component ToggleButton
MeowLynxSea edited this page Jan 24, 2026
·
5 revisions
A selectable button (useful for segmented controls or filters).
ToggleButton can work as:
- A standalone toggle (selected/unselected)
- A mutually-exclusive group (segmented control) via
.group("...")
- Segmented controls (view modes, filters, tabs)
- Toggleable toolbar buttons (bold/italic/etc.)
Not a good fit:
- Boolean settings (use
SwitchorCheckbox)
use gpui::ElementId;
use yororen_ui::component::toggle_button;
let view = toggle_button("Bold")
.key(("toolbar", "bold"))
.default_selected(false)
.on_toggle(|selected, _ev, _window, _cx| {
// ...
});- Use
.group("...")to create a mutually exclusive group.
-
toggle_button("..."): constructor -
id(...) / key(...): stable identity -
selected(bool): set selected (controlled) -
default_selected(bool): initial selection for group/internal state disabled(bool)variant(ActionVariantKind)-
group("..."): group id for mutually exclusive selection on_toggle(|selected, ev, window, cx| ...)- Styling:
bg/selected_bg/hover_bg
- Without
on_toggle, the button manages its own selected state (keyed by id). - With
.group("..."), clicking selects the current button and deselects others in the group.
- Height:
36px - Padding:
px_4+py_2 - Corner radius:
rounded_md
Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.