radio_button

Function radio_button 

Source
pub fn radio_button(args: impl Into<RadioButtonArgs>, state: RadioButtonState)
Expand description

§radio_button

Render a Material Design 3 radio button with a smooth animated selection dot.

§Usage

Use in single-choice groups where exactly one option should be active.

§Parameters

  • args — configures sizing, colors, and callbacks; see RadioButtonArgs.
  • state — a clonable RadioButtonState that manages selection animation and ripple feedback.

§Examples

use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
use tessera_ui::tessera;
use tessera_ui_basic_components::radio_button::{radio_button, RadioButtonArgsBuilder, RadioButtonState};

#[derive(Clone, Default)]
struct DemoState {
    selected: Arc<AtomicBool>,
    radio: RadioButtonState,
}

#[tessera]
fn radio_demo(state: DemoState) {
    let on_select = Arc::new({
        let selected = state.selected.clone();
        move |is_selected| {
            selected.store(is_selected, Ordering::SeqCst);
        }
    });

    radio_button(
        RadioButtonArgsBuilder::default()
            .on_select(on_select)
            .build()
            .unwrap(),
        state.radio.clone(),
    );

    state.radio.set_selected(true);
    assert!(state.radio.is_selected());
    state.radio.set_selected(false);
    assert!(!state.radio.is_selected());
}