Skip to content

Component SearchInput

MeowLynxSea edited this page Jun 13, 2026 · 5 revisions

SearchInput

A single-line text input with a leading search icon and a trailing clear (×) button when non-empty. Escape clears the value.

Import

use yororen_ui::headless::search_input::search_input;

Minimal example

use yororen_ui::headless::search_input::search_input;

search_input("search-box")
    .placeholder("Search…")
    .value(self.query.clone())
    .on_change({
        let entity = cx.entity();
        move |new: &str, _window, cx| {
            entity.update(cx, |s, _cx| s.query = new.to_string());
        }
    })
    .on_clear(|_window, _cx| {
        // Called after the renderer has already cleared the input.
    })
    .render(cx, window)

Props

Method Purpose
placeholder(text) Hint shown when empty.
value(s) Current value (a String-like type, owned).
disabled(v) Disable interaction.
on_change(closure) Fn(&str, &mut Window, &mut App) + 'static + Send + Sync. Fired on each accepted change.
on_submit(closure) Fn(&str, &mut Window, &mut App) + 'static + Send + Sync. Fired on Enter.
on_clear(closure) Fn(&mut Window, &mut App) + 'static + Send + Sync. Fired when the user dismisses the value (Escape, × click).

Notes

  • Factory takes (id) only — the focus handle and the keyed state are minted by the renderer.
  • .render(cx, window) is two-arg and returns AnyElement. The window is required because the renderer hooks the EntityInputHandler for IME / paste.
  • on_change receives &str (the new UTF-8 text), not SharedString. Convert with .to_string() before storing in your view.
  • on_clear is a two-argument callback (&mut Window, &mut App) — there is no value argument because the renderer has already cleared the input by the time it fires.

See also

TextInput, PasswordInput, KeybindingInput

Clone this wiki locally