Skip to content

Component RadioGroup

MeowLynxSea edited this page Jun 18, 2026 · 4 revisions

RadioGroup

A wrapper that ensures exactly one Radio child is selected. The parent owns selected and the radios.

use yororen_ui::headless::radio::radio;
use yororen_ui::headless::radio_group::radio_group;

radio_group("theme", cx)
    .name("theme")
    .selected(self.theme_idx)
    .on_change({
        let entity = cx.entity();
        move |new, _, cx| entity.update(cx, |s, _| s.theme_idx = new);
    })
    .child(radio("theme-light", cx).checked(self.theme_idx == 0).render(cx))
    .child(radio("theme-dark",  cx).checked(self.theme_idx == 1).render(cx))
    .render(cx)

Props

Method Purpose
name(s) Group name. Drives Tab order dedupe and a11y.
selected(i) Index of the currently selected radio.
on_change(closure) Fn(usize, &mut Window, &mut App) + 'static + Send + Sync. Fired with the new index.
child(stateful) A rendered Radio element.

Each child's own on_toggle is overridden by the group's selection.

.render(cx) returns Stateful<Div>. No state entity.

See also: Radio, Checkbox, Switch.

Clone this wiki locally