Component

native select

dx components add native_select

A styled native <select>, for when the platform's own picker is preferable to a custom listbox.

Selected: apple

Installation

Use the CLI command for the common path, or copy the component files manually.

Manual installation files

Copy the component source and CSS into your app. Import the shared theme CSS once near your app root.

use dioxus::prelude::*;
use dioxus_icons::lucide::ChevronDown;

/// A styled native `<select>` -- for the common case where the full custom
/// listbox behaviour of [`Select`](crate::components::select::Select)
/// (search, portalled popover, custom option rendering) isn't needed and
/// the platform's own picker (native mobile wheel, OS-native styling) is
/// preferable. Wraps a plain `<select>`, so it comes with the browser's
/// own keyboard/typeahead/form-participation behaviour for free -- there is
/// no APG contract to add on top, and no primitive underneath.
#[component]
pub fn NativeSelect(
    onchange: Option<EventHandler<FormEvent>>,
    oninput: Option<EventHandler<FormEvent>>,
    onfocus: Option<EventHandler<FocusEvent>>,
    onblur: Option<EventHandler<FocusEvent>>,
    #[props(extends = GlobalAttributes)]
    #[props(extends = select)]
    attributes: Vec<Attribute>,
    children: Element,
) -> Element {
    rsx! {
        document::Link { rel: "stylesheet", href: asset!("/src/components/native_select/style.css") }
        div { class: "dx-native-select-wrapper",
            select {
                class: "dx-native-select",
                onchange: move |e| _ = onchange.map(|callback| callback(e)),
                oninput: move |e| _ = oninput.map(|callback| callback(e)),
                onfocus: move |e| _ = onfocus.map(|callback| callback(e)),
                onblur: move |e| _ = onblur.map(|callback| callback(e)),
                ..attributes,
                {children}
            }
            ChevronDown { class: "dx-native-select-icon" }
        }
    }
}

Usage notes

The Native Select component is a styled native <select>, for the common case where the browser's own picker is preferable to a fully custom listbox. It comes with the platform's own keyboard, typeahead, and form-participation behaviour for free.

Component Structure

NativeSelect {
    value: "{fruit}",
    onchange: move |e: FormEvent| fruit.set(e.value()),
    option { value: "apple", "Apple" }
    option { value: "banana", "Banana" }
}