Skip to content

Component RadioGroup

MeowLynxSea edited this page Jan 24, 2026 · 4 revisions

RadioGroup

A group of radio options.

RadioGroup renders a vertical list of selectable options. It can be used in controlled or uncontrolled mode.

Example

use gpui::ElementId;
use yororen_ui::component::{radio_group, RadioOption};

let view = radio_group()
    .key(("settings", "theme"))
    .options([
        RadioOption::new("light", "Light"),
        RadioOption::new("dark", "Dark"),
    ])
    .on_change(|value, _ev, _window, _cx| {
        // ...
    });

When to use

  • Small mutually exclusive sets (theme, mode, region)

API

  • radio_group(): constructor
  • id(...) / key(...): stable identity
  • options([...]) / option(RadioOption)
  • value(String): set selected value (controlled)
  • disabled(bool): disable entire group
  • tone(Hsla): set accent color for all radios
  • on_change(|value, ev, window, cx| ...): fired when selection changes
  • render_option(|option, radio| -> AnyElement): custom option row rendering

Notes

  • If on_change and value are both omitted, the group manages its own selected value.

Defaults

  • Layout: vertical (flex_col) with a small gap between options
  • Options are clickable rows by default; use render_option(...) to supply a custom row layout

Example: Custom option layout

use gpui::div;
use yororen_ui::component::{label, radio_group, RadioOption};

let view = radio_group()
    .options([
        RadioOption::new("stable", "Stable"),
        RadioOption::new("beta", "Beta"),
    ])
    .render_option(|opt, radio| {
        div()
            .flex()
            .items_center()
            .justify_between()
            .gap_3()
            .child(div().flex().items_center().gap_2().child(radio).child(opt.label.clone()))
            .child(label(opt.value.clone()).mono(true).muted(true))
            .into_any_element()
    });

Clone this wiki locally