Radio Group
A set of options where exactly one can be selected.
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 radio-group
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase radio-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::radio_group::{
RadioGroupIndicator,
RadioGroupRadio,
RadioGroupRoot,
};
RadioGroupRoot::new()
.child(
RadioGroupRadio::new()
.child(
RadioGroupIndicator::new(),
),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#RadioGroupRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::radio_group::RadioGroupRoot;
RadioGroupRoot::new()
.id("example-id")
.name("name")
.form(/* form: impl Into<SharedString> */)
.default_value(None)
.value(None)
.disabled(true)
.read_only(true)
.required(true)
.aria_label("aria label")
.on_value_change(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a RadioGroupRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<RadioGroupChild<T>>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<RadioGroupChild<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. |
.name | pub fn name(mut self, name: impl Into<SharedString>) -> Self
Sets the form field name used when serializing or submitting the value. |
.form | pub fn form(mut self, form: impl Into<SharedString>) -> Self
Sets the form configuration for this part. |
.default_value | pub fn default_value(mut self, default_value: Option<T>) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.value | pub fn value(mut self, value: Option<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. |
.read_only | pub fn read_only(mut self, read_only: bool) -> Self
When true, allows presentation and focus behavior without permitting value changes. |
.required | pub fn required(mut self, required: bool) -> Self
Marks the control as required for validation and accessibility state. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Sets the accessible label announced by screen readers. This is the literal-string substitute for Base UI's |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(Option<&T>, &mut RadioGroupValueChangeDetails, &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(RadioGroupRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. RadioGroupRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#RadioGroupIndicator
Visual representation of the component's current state or value.
use base_gpui::radio_group::RadioGroupIndicator;
RadioGroupIndicator::new()
.keep_mounted(true)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a RadioGroupIndicator with its default configuration. |
.keep_mounted | pub fn keep_mounted(mut self, keep_mounted: bool) -> Self
Keeps the part mounted when inactive or closed so child state can be preserved. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(RadioGroupIndicatorStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. RadioGroupIndicator also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#RadioGroupRadio
Public renderable part of the Radio Group Radio component.
use base_gpui::radio_group::RadioGroupRadio;
RadioGroupRadio::new()
.id("example-id")
.value(/* value: T */)
.disabled(true)
.read_only(true)
.required(true)
.aria_label("aria label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a RadioGroupRadio with its default configuration. |
.child | pub fn child(mut self, child: impl Into<RadioGroupRadioChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<RadioGroupRadioChild>>,) -> 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. |
.value | pub fn value(mut self, value: 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. |
.read_only | pub fn read_only(mut self, read_only: bool) -> Self
When true, allows presentation and focus behavior without permitting value changes. |
.required | pub fn required(mut self, required: bool) -> Self
Marks the control as required for validation and accessibility state. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Sets the accessible label announced by screen readers. This is the literal-string substitute for Base UI's |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(RadioGroupRadioStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. RadioGroupRadio 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.