SearchBar
Mobile search convention in one component: pill input (with built-in magnifier) + clear button + search button (Enter works the same) + cancel button (hide with hide-cancel) + a convention panel on focus — when the value is empty it shows the history / hot-keyword slot groups; once a value is typed it switches to the suggestions slot group (the same grouping mainstream shopping apps use). value is dual-channel; oas-search / oas-cancel events; history persistence is owned by the host (the component stores nothing — the host writes localStorage and renders into the slot).
Boundary with oas-input: oas-input is the general text input (it already supports prefix-icon="search" + enterkeyhint="search"); search-bar does not duplicate the input control itself — it owns the search-page conventions: the trigger semantics (single oas-search exit), the cancel exit, and the slot grouping for history / hot keywords / suggestions. See the component README for the full boundary.
Basic search
Enter or the search button fires oas-search (detail { value }; empty values do not fire); typing writes the value attribute in real time and fires oas-input (the host can render suggestions from it); the clear button empties and fires oas-input (focus returns to the input):
Basic search (Enter / search button / clear)
Type and press Enter (or click the search button) to see the oas-search feedback.
History & hot keywords slots
The history / hot slots render history and hot keywords (persistence owned by the host — the demo keeps an in-memory array), shown when the value is empty and the input is focused; clicks inside the panel keep focus via the panel's pointerdown guard (history chips stay clickable); Esc collapses the panel, refocusing expands it again:
History + hot keywords (expand on focus, click to fill)
Focus the input → the panel shows history / hot keywords; click a chip to fill and search.
Suggestions slot
The suggestions slot shows when a value is present and the input is focused (the empty/filled grouping is driven by the component); the host listens to oas-input and renders suggestion items:
Suggestions (type to see suggestions)
Type “shoe” to see suggestions; click one to fill and search.
Variants: cancel / hide-cancel / disabled
hide-cancel hides the cancel button (for toolbars that already have an exit); disabled disables the input and all buttons; the cancel button fires oas-cancel (detail carries the pre-clear value, the host may restore it); the component then clears and collapses the panel:
Cancel button / hide-cancel / disabled
Click the cancel button on the first row to see the oas-cancel feedback.
Keyboard & accessibility
- Input uses
type="search"(implicit searchbox semantics) +aria-label(i18n, not placeholder-dependent) +enterkeyhint="search"; Enter searches, Esc collapses the panel. - Search / clear buttons are icon-only with
aria-label(“Search” / “Clear search input”); the clear button is out of the Tab order (Tab order = input → search → cancel); the cancel button has visible text. - The panel is companion content (not an overlay): slot content semantics belong to the host (history buttons carry their own accessible names); the panel's
pointerdownpreventDefault keeps focus — input elements inside host slots need their own focus handling. - RTL mirrors via logical properties; colors are token-based (dark theme follows automatically).
Custom styling notes
::part(field) is the pill row (magnifier ::part(lead-icon) + ::part(input) + ::part(clear)); ::part(go) is the search button and ::part(cancel) the cancel button; the convention panel ::part(panel) contains the three group containers ::part(suggestions) / ::part(history) / ::part(hot) (visibility driven by value). Override ::part(go) background to restyle the search button.
API
oas-search-bar
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
disabled | Disables the input and all buttons (config-provider injected disabled applies too) | boolean | — |
hide-cancel | Hides the cancel button (for toolbars that already have an exit) | boolean | — |
placeholder | Placeholder text, defaults to i18n “Search products” (host overridable) | — | — |
value | Current input value. Typing writes the attribute in real time and fires oas-input (the host can render suggestions); empty values never fire oas-search | string | number | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
value | Current input value: get+set dual channel, writes reflect the value attribute (no events on assignment) | string | number | — |
Events
| Event | Description |
|---|---|
oas-cancel | Cancel button, detail: { value } carries the pre-clear value (the host may restore it); the component then clears and collapses the panel |
oas-input | Fires on every input (the clear button fires it too — hosts listening only to oas-input never miss a clear), detail: { value } |
oas-search | Enter or the search button, detail: { value }; empty values do not fire |
Slots
| Name | Description |
|---|---|
history | History keywords (shown when empty + focused; persistence owned by the host — render chips and record them yourself) |
hot | Hot keywords (shown when empty + focused, grouped beside history) |
suggestions | Suggestions (shown when filled + focused; render dynamically from oas-input) |