Skip to main content

radio_group

Function radio_group 

Source
pub fn radio_group<S, T: Serialize + PartialEq, L: Into<String>>(
    title: impl Into<String>,
    selected: Sig<S, T>,
    options: impl IntoIterator<Item = (T, L)>,
) -> El<S>
Expand description

A group of radio buttons with title in its <legend>, one per option, that sets selected to the option’s value.

The radios share a name derived from the signal’s path, so the browser gives the group one Tab stop and moves between its radios with the arrow keys. The <fieldset> and <legend> name the group for a screen reader.

use hypersig::Signals;
use hypersig_ui::radio_group;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
enum Plan {
    Free,
    Pro,
}

#[derive(Signals, Serialize, Deserialize)]
struct Billing {
    plan: Plan,
}

let plans = radio_group("Plan", Billing::plan(), [(Plan::Free, "Free"), (Plan::Pro, "Pro")]);
assert!(plans.render().contains(r#"name="ui-plan-radio""#));