Toggle Group
A row of toggles where one or several can be pressed.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase toggle-group
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase toggle-group
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::toggle_group::{
ToggleGroup,
};
ToggleGroup::new();
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#ToggleGroup
Groups related child parts and coordinates their shared behavior.
use base_gpui::toggle_group::ToggleGroup;
ToggleGroup::new()
.id("example-id")
.aria_label("aria label")
.default_value(/* default_value: Vec<T> */)
.value(/* value: Vec<T> */)
.disabled(true)
.orientation(/* orientation: ToggleGroupOrientation */)
.multiple(true)
.loop_focus(true)
.on_value_change(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToggleGroup with its default configuration. |
.child | pub fn child(mut self, child: impl Into<ToggleGroupChild<T>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<ToggleGroupChild<T>>>,) -> Self
Adds multiple typed children in iteration order. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Sets a literal accessible name for this part. |
.default_value | pub fn default_value(mut self, default_value: Vec<T>) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.value | pub fn value(mut self, value: Vec<T>) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.orientation | pub fn orientation(mut self, orientation: ToggleGroupOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.multiple | pub fn multiple(mut self, multiple: bool) -> Self
Controls whether more than one value may be selected at the same time. |
.loop_focus | pub fn loop_focus(mut self, loop_focus: bool) -> Self
Controls whether keyboard focus wraps from the last enabled item to the first and vice versa. |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(&[T], &mut ToggleGroupValueChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when value change occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToggleGroupStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToggleGroup also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.