Forms

Radio Group

Select exactly one value from a set.

Rust
1use herogpui::components::radio_group::RadioGroup;

Usage

Option content uses 14px medium text with 20px lines, independent of surrounding line height.

Rust
1use herogpui::prelude::RadioGroup;
2
3RadioGroup::new("radio-group", plans())
4    .default_value("Free")
5    // v3's own example opens with the group's `<Label>` and
6    // `<Description>`, then a `<Description>` per `<Radio>`.
7    .label("Plan selection")
8    .description("Choose the plan that suits you best")
9    .descriptions([
10        Some("Includes 100 messages per month"),
11        Some("Includes 200 messages per month"),
12        None,
13    ])

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

RadioGroupRadioOption

Radio Group is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Radio Group uses.

Styling

Radio Group styling
StyleDescription
text_size + line_heightOption content uses 14px medium text with 20px lines, independent of surrounding line height.
RadioGroup::render root flex_col + gap(px(4.))Group root around label, description, options and field error.
vertical group gap(px(16.))Sixteen-pixel vertical option spacing.
flex + items_center + flex_wrap + gap(px(16.))Wrapping horizontal option row.
per-option flex_col + gap(px(4.))Option root with sibling description.
pl(circle + gap) + DescriptionHelp text aligned under the label at 28px logical-start padding.
gap(px(12.)) + text_size(px(14.)) + FontWeight::MEDIUMClickable control and label row.
16px + key_radius + field background/shadowPrimary selection box and field chrome.
dot px(6.) / pressed px(8.)Built-in foreground dot geometry.
FieldVariant::Secondary + colors.default.colorLower-emphasis surface variant.

API reference

Builders

Radio Group builders
BuilderTypeDefaultDescription
value(value)stringCurrent selected value (controlled).
default_value(value)stringInitial selected value (uncontrolled).
on_change(callback)Fn(value: string) -> ()Handler called with the selected option value.
is_disabled(bool)boolfalseDisables every option and removes the group from the tab order.
is_required(bool)boolfalseRequires one selected value for form submission.
is_read_only(bool)boolfalseKeeps roving focus active while preventing value changes.
is_invalid(bool)boolfalseMarks the group and each radio control invalid.
variant(FieldVariant)FieldVariantFieldVariant::PrimaryPrimary field chrome or the flat surface treatment.
name(value)stringShared submitted name for the selected radio value.
orientation(Orientation)OrientationOrientation::VerticalLayout and arrow-key orientation.
new(id, options)id, optionsCompound label, description, radios and field error; root render props are not exposed as one closure.
option_content(render)AnyElement | RadioFieldrender closureStatic option labels and state-driven content are supported, but arbitrary part ordering is not.
indicator(render)AnyElementCustom content inside the control wrapper.
option_content(render) + indicator(render)render) + indicator(renderCurrent option selection supplied to a custom renderer.

Parts

Radio Group parts
PartDescription
RadioGroupSingle-selection, form, validation and roving-focus owner.
RadioGroupOptional group label with required and invalid state.
RadioGroupGroup-level or per-option help text.
RadioOptionOne option field with its own value and disabled state.
RadioGroupClickable row containing the control and label; arbitrary child ordering is not exposed.
RadioGroupFocusable 16px selection control.
RadioGroupBuilt-in selected dot or caller-rendered indicator.
RadioGroupGroup-level or per-radio validation text outside clickable content.

States

Radio Group states
BuilderStateDescription
selected == Some(index)SelectedAccent control and foreground indicator show the chosen option.
interaction feeds the pressed dot onlyHoveredChanges the unselected indicator fill and field border on hover; does not reproduce those hover layers.
tab_stop_handle + with_focus_ringFocus visibleThe roving keyboard stop rings the current control.
anim::pressed + interaction is_pressedPressedThe control shrinks to 95%, the selected fill hovers and the dot grows from 6px to 8px.
RadioGroup::is_disabledDisabled groupEvery option is dimmed, inert and absent from the tab order.
RadioOption::is_disabledDisabled optionOne option is dimmed and skipped by pointer and arrow navigation.
is_read_only gates selection after cursor movementRead onlyArrows move focus while selection remains unchanged.
self.is_invalid || group error || option errorInvalidGroup invalid state outlines every control; a per-radio error outlines only its own control.
Orientation::VerticalVerticalOptions stack and all four radio arrows rove through them.
Orientation::HorizontalHorizontalOptions wrap in a row while radio-group arrows retain four-arrow contract.