SearchBox
A labelled search box; the list it filters waits for a pause in typing (useDebounced).
import { SearchBox } from '@ergasti/bricks';Examples
Filter row
The older labelled search and select, in the Filters row (ListToolbar is the standard now; see Deprecated APIs). hideLabel keeps the label for screen readers only.
Code
import { useState } from 'react';
import { Filters, SearchBox, SelectBox } from '@ergasti/bricks';
function Row() {
const [q, setQ] = useState('');
const [tier, setTier] = useState('');
return (
<Filters>
<SearchBox id="docs-q" label="Search" value={q} onChange={setQ} />
<SelectBox id="docs-tier" label="Tier" hideLabel value={tier} onChange={setTier} options={[['', 'All tiers'], ['rising', 'Rising'], ['elite', 'Elite']]} />
</Filters>
);
}Props
Prop
Type
Design guidance
How the BRICKS design system uses SearchBox. Written in docs/content/components/SearchBox.md; the props above are read from the code, which wins where the two disagree.
A labelled search field for filtering a list; use it inside Filters on 0.1.x lists.
SearchBox is a <label> over an <input type="search"> (dir="auto", no autocomplete, 100 characters max). It is controlled: you hold the value and debounce the fetch in the list that reads it. v3 screens use ListToolbar's search slot (with an icon, built-in debounce and a clear button).
Anatomy
- Wrapper (
div.console-list-search): column, 5px gap. - Label (
label for={id}): 13px 500. - Input (
input type="search"): 44px tall on its own (console list style), 10px radius,#D9DFEAborder; insideFiltersit takes--control-h(38px on desktop, 44px on touch screens).
Variants
None. Inside Filters it takes the row's free space and --control-h height.
States
| State | Trigger | Look |
|---|---|---|
| Empty | value="" | Empty field |
| With value | text | Native search clear (×) where the browser shows one |
| Focus-visible | focus | Console focus outline |
| Mixed script | Arabic typed | dir="auto" flips the field |
Usage
const [q, setQ] = useState('');
const query = useDebounced(q, 300);
<Filters>
<SearchBox id="coupon-q" label="Search coupons" value={q} onChange={setQ} />
</Filters>Where it appears
- 0.1.x console lists. v3:
ListToolbar search. - Kit gallery.
Guidelines
Do
- Debounce before fetching.
- Say what is searched in the label ("Search coupons").
Don't
- Don't rely on a placeholder instead of the label.
RTL and Arabic
dir="auto"per value.
Tokens
None (console colours); inside Filters: --control-h, --color-control-border.
Accessibility
- A real
<label for>names the field;type="search"exposes it as a searchbox (it is not asearchlandmark: wrap the list's controls in<search>orrole="search"yourself if you want one). dir="auto"reads mixed-language input in the right order.- No kit focus rule targets it: it shows the browser's default focus outline.
- The list it filters does not announce results by itself; pair it with a polite result count (
Pager's summary does this).
Found in the source
- Roles in the markup:
alert. - ARIA attributes set:
aria-label,aria-live,aria-hidden,aria-current.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
ListToolbar(search): v3.HeaderSearch: the topbar search.Filters,SelectBox.
See also: FormField · SaveBar · Segmented
Source
src/kit/ListControls.tsx (line 8) on GitHub.