# components/SearchField (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/components/SearchField.tsx](https://github.com/Tahul/zidane/blob/main/ui/src/components/SearchField.tsx).

## Components

### `SearchField`

Component.

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

```ts
function SearchField(props: SearchFieldProps): Element
```

**Parameters**

- `props` (`SearchFieldProps`): Component props.

**Returns** `Element`

**Props**

- `autoFocus?` (`boolean`, default `false`): Takes focus when it mounts (the search at the top of a menu).
- `className?` (`string`): Extra classes on the root.
- `label` (`string`): 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.
- `query` (`string`): The query.
- `size?` (`'sm' | 'md'`, default `'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'`, default `'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.

Source: [ui/src/components/SearchField.tsx:44](https://github.com/Tahul/zidane/blob/main/ui/src/components/SearchField.tsx#L44)

## Functions

### `filterByQuery`

Function.

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

```ts
function filterByQuery<T>(
  list: readonly T[],
  query: string,
  words: (item: T) => readonly (string | undefined)[],
): readonly T[]
```

**Type parameters**

- `T`

**Parameters**

- `list` (`readonly T[]`): The items.
- `query` (`string`): The query.
- `words` (`(item: T) => readonly (string | undefined)[]`): An item's words.

**Returns** `readonly T[]`

Source: [ui/src/components/SearchField.tsx:88](https://github.com/Tahul/zidane/blob/main/ui/src/components/SearchField.tsx#L88)

## Interfaces

### `SearchFieldProps`

Interface.

Props for [`SearchField`](https://zidane.si/docs/reference/ui-components-search-field.md#SearchField).

```ts
interface SearchFieldProps
```

**Properties**

- `autoFocus?` (`boolean`, default `false`): Takes focus when it mounts (the search at the top of a menu).
- `className?` (`string`): Extra classes on the root.
- `label` (`string`): 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.
- `query` (`string`): The query.
- `size?` (`'sm' | 'md'`, default `'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'`, default `'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.

Source: [ui/src/components/SearchField.tsx:10](https://github.com/Tahul/zidane/blob/main/ui/src/components/SearchField.tsx#L10)
