Function freya::components::Dropdown

source ·
pub fn Dropdown<T>(props: DropdownProps<T>) -> Option<VNode>
where T: PartialEq + Clone + Display + 'static,
Expand description

Select from multiple options, use alongside DropdownItem.

§Styling

Inherits the DropdownTheme theme.

§Example


fn app() -> Element {
    let values = use_hook(|| vec!["A".to_string(), "B".to_string(), "C".to_string()]);
    let mut selected_dropdown = use_signal(|| "A".to_string());
    rsx!(
        Dropdown {
            value: selected_dropdown.read().clone(),
            for ch in values {
                DropdownItem {
                    value: ch.to_string(),
                    onclick: {
                        to_owned![ch];
                        move |_| selected_dropdown.set(ch.clone())
                    },
                    label { "{ch}" }
                }
            }
        }
    )
}