SearchWidget
A search widget: a query box with an always-visible results list.
Basic usage
The component doesn't set a height on its own: query and results are absolutely positioned and the root element carries no height. It's recommended to give the root element a height (a fixed height, height: 100%, or flex: 1 in a flex column all work), otherwise the results list overflows the widget box. The demo also adds position: relative to the root so those regions anchor to the widget itself (by default they anchor to the nearest positioned ancestor).
Query and choosing
value/defaultValue/onQueryChangeare the query box's controlled/uncontrolled channels (there is noonChange; query changes go throughonQueryChange).- Each
resultsitem is standard option data (withvalueandchildren). onChoosefires when a result is chosen (Enter on the highlighted result, or clicking one). The highlight clears whenever the results set or query changes.- The component implements no searching; real use is mostly async: fire the request in
onQueryChange, optionally emptyresultswhile loading and fill them in when ready — the highlight clears automatically on every results/query change, no manual reset needed. inputPropsis a two-layer channel: SearchInput-level props are passed directly; props meant for the native<input>(aria-*,autoComplete, etc.) go throughinputProps.inputProps(TextInput's input-element channel).inputProps.inputRefis merged — that input doubles as the focus owner for the results list'saria-activedescendant.
Keyboard and focus
Focus always stays in the query box: ↑↓ move the highlight among results (wrapping at the ends), Enter chooses the current highlight. The clear indicator on the query box comes from SearchInput — it appears when there's a value and clears on click.
API
See also
- Lookup with candidates, shown as tags: MenuTagMultiselect
- A free-input dropdown of candidates: ComboBoxInput
- The query box itself: SearchInput