lumen-dioxus 6.0.0

Lumen UI components for Dioxus: web, desktop, mobile, and Dioxus Native (Blitz).
Documentation
//! `SearchField`: a search input.

use dioxus::prelude::*;

use crate::class::compose;

/// Props for [`SearchField`].
#[derive(Props, Clone, PartialEq)]
pub struct SearchFieldProps {
    /// The native input type. Defaults to `search`.
    #[props(default = "search".to_string(), into)]
    pub r#type: String,
    /// Extra classes appended after the Lumen classes.
    #[props(into)]
    pub class: Option<String>,
    /// Fires on every edit.
    pub oninput: Option<EventHandler<FormEvent>>,
    /// Fires when the value is committed.
    pub onchange: Option<EventHandler<FormEvent>>,
    /// Fires on every key press, for example to clear the query on Escape.
    pub onkeydown: Option<EventHandler<KeyboardEvent>>,
    /// Any other `<input>` or global attribute, such as `value`, `placeholder`, or `aria_label`.
    #[props(extends = GlobalAttributes, extends = input)]
    pub attributes: Vec<Attribute>,
}

/// A text input for search queries. Name it with a `Label`, `aria_label`, or `aria_labelledby`.
#[component]
pub fn SearchField(props: SearchFieldProps) -> Element {
    let class = compose([Some("ui-input ui-search-field"), props.class.as_deref()]);
    let (oninput, onchange, onkeydown) = (props.oninput, props.onchange, props.onkeydown);

    rsx! {
        input {
            class,
            r#type: props.r#type,
            oninput: move |event| {
                if let Some(handler) = oninput {
                    handler.call(event);
                }
            },
            onchange: move |event| {
                if let Some(handler) = onchange {
                    handler.call(event);
                }
            },
            onkeydown: move |event| {
                if let Some(handler) = onkeydown {
                    handler.call(event);
                }
            },
            ..props.attributes,
        }
    }
}