Search

Search

Search is a legacy migration surface: a bordered search field with a leading magnifier, a trailing action, and a suggestions dropdown for the queries you hand it. It owns its text, filters the suggestions by substring, and opens the dropdown from a portal so the panel is not clipped by the field's container. They are legacy migration surfaces kept for existing pages; new code should prefer SearchInput, the bare search field that leaves the suggestion panel to the host.

  • Reach for it while migrating a page that already uses this shape: a search box that filters its own suggestion list and opens a portal panel on focus.
  • The field is uncontrolled — it stores what is typed — and every keystroke is reported to on_search, so a host can filter externally too.
  • For a plain search box, SearchInput ships the same leading glyph and clear affordance without a dropdown.

Import

rust
1
2
use hikari_components::*;          // Search
use hikari_components::prelude::*; // rsx!, VNode, EventHandler

The Rust form is a plain function, Search(SearchProps { … }). Inside rsx! every prop may be omitted except the three required ones — value, placeholder and suggestions. The examples below omit the imports the page has just shown.

Value, placeholder and suggestions

value seeds the field, placeholder labels it while empty, and suggestions is the query pool. Suggestions are filtered by substring, case-insensitively, against what the field currently holds; while the field is empty the dropdown stays closed (and the pool is not shown at all). A snapshot cannot open the dropdown — it opens on focus — so the examples show the resting field.

Rust

Trailing action: clear, submit, loading

The trailing slot always holds exactly one control. While the field has text and is enabled it is the clear button (allow_clear, on by default); when the field is empty it is the submit arrow, which reports the value to on_search; while loading is set it is a spinner glyph and both actions step aside; and with allow_clear turned off a non-empty field keeps the submit arrow too.

Rust

Reporting queries and picks

on_search fires with the whole field value on every keystroke, on the submit arrow, and with the picked suggestion when a suggestion is clicked in the dropdown; on_suggestion_click fires with that same suggestion just before it, and on_clear fires when the clear button empties the field. glow toggles the field's highlight (on by default), and class / style land on the outer wrapper.

The examples on this page build the portal surface the dropdown needs before the tree: Search reads a portal context from its ancestors, so a bare Search without one panics. A real host puts a portal provider around the whole page instead; the snippet below is the minimal stand-in for a snapshot.

Rust

API

Rust

Props — Search

PropTypeDefaultDescription
valueString""—
placeholderString""—
disabledboolfalse—
loadingboolfalse—
allow_clearbooltrue—
suggestionsVec<String>[]—
on_searchEventHandler<String><code>EventHandler::new(|_| {})</code>—
on_clearOption<EventHandler<()>>None—
on_suggestion_clickOption<EventHandler<String>>None—
classString""—
styleString""—
glowbooltrue—

Notes

  • The field is uncontrolled: it seeds from value and keeps its own text afterwards. Changing value from the host does not move the caret back — read the field through on_search and treat value as an initial value.
  • The dropdown is a portal entry positioned under the field, so it escapes the field's own overflow; Search requires a portal context above it in the tree and panics without one. The dropdown closes on Escape (while the field has focus), on a suggestion pick, and on the clear button.
  • A suggestion pick sets the field to that suggestion, then reports it to on_suggestion_click (if given) and to on_search.
  • Suggestions are only offered while the field has text, so an empty field opens nothing — the submit arrow is the empty-state action.
  • glow toggles the highlight preset the field wrapper carries; the blur, intensity and colour of that preset are fixed by this component, not by props.

Accessibility

  • The field is a <input type="search">: it carries the platform's own search semantics, and placeholder is the only label, so give the page a visible label or an aria-label of its own.
  • The trailing clear and submit controls are icon buttons without an aria-label; a screen-reader user cannot tell them apart from their glyphs. When the action matters, mirror it in visible chrome.
  • Keyboard: Escape closes the suggestion dropdown while the field has focus; Enter is the browser's own — the component does not intercept it.
  • The dropdown has no listbox roles, so its suggestions are pointer-only in practice; give an equivalent visible path for anything important.

Related components

  • SearchInput — the bare search field: leading glyph, clear affordance, no dropdown.
  • AutoComplete — a suggestion field whose dropdown is inline rather than in a portal.
  • Input — the general text field, with caption, hint and error line.