Skip to content

components/SearchField

import { … } from 'zidane-ui'ui/src/components/SearchField.tsx

Components#

SearchFieldComponent#

A list's search field: a well with the magnifier. Escape clears it, instead of closing the surface it sits in.

TypeScript
function SearchField(props: SearchFieldProps): Element
Parameters
NameTypeDescription
propsSearchFieldProps

Component props.

Element
SearchField props
NameTypeDefaultDescription
autoFocus?booleanfalse

Takes focus when it mounts (the search at the top of a menu).

className?string

Extra classes on the root.

labelstring

Its accessible name and placeholder, from the area's labels.

onKeyDown?(event: KeyboardEvent<HTMLInputElement>) => void

Keys the field leaves to its list (ArrowDown into the rows, Enter to pick the first).

onQuery(query: string) => void

Called with the new query.

querystring

The query.

size?'sm' | 'md''md'

Its height: md over a list, sm in a card's header beside its other controls.

style?CSSProperties

Inline styles on the root element.

variant?'well' | 'strip''well'

well: a field set into its surface. strip: a list's header inside a card's tray (FormSection, 4px padding): borderless, through the tray's padding edge to edge, the magnifier where the rows' text starts (16px in), a hairline under it that takes the focus colour. size applies to well only.

ui/src/components/SearchField.tsx:44

Functions#

filterByQueryFunction#

The items whose words hold the query, in any case. An empty query keeps them all.

TypeScript
function filterByQuery<T>(
  list: readonly T[],
  query: string,
  words: (item: T) => readonly (string | undefined)[],
): readonly T[]
Type parameters
NameDescription
T
Parameters
NameTypeDescription
listreadonly T[]

The items.

querystring

The query.

words(item: T) => readonly (string | undefined)[]

An item's words.

readonly T[]

ui/src/components/SearchField.tsx:88

Interfaces#

SearchFieldPropsInterface#

Props for SearchField.

TypeScript
interface SearchFieldProps
SearchFieldProps properties
NameTypeDefaultDescription
autoFocus?booleanfalse

Takes focus when it mounts (the search at the top of a menu).

className?string

Extra classes on the root.

labelstring

Its accessible name and placeholder, from the area's labels.

onKeyDown?(event: KeyboardEvent<HTMLInputElement>) => void

Keys the field leaves to its list (ArrowDown into the rows, Enter to pick the first).

onQuery(query: string) => void

Called with the new query.

querystring

The query.

size?'sm' | 'md''md'

Its height: md over a list, sm in a card's header beside its other controls.

style?CSSProperties

Inline styles on the root element.

variant?'well' | 'strip''well'

well: a field set into its surface. strip: a list's header inside a card's tray (FormSection, 4px padding): borderless, through the tray's padding edge to edge, the magnifier where the rows' text starts (16px in), a hairline under it that takes the focus colour. size applies to well only.

ui/src/components/SearchField.tsx:10