# Search field

Source: https://ecosphere.dev/docs/forms/search-field (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

The page search bar and the compact finder with its filter.

`import { EcoSearchField } from "vue-ecosphere"`

## Page search

Type and press Enter; Escape or the clear button empties it.

Vue (vue-ecosphere):

```vue
<EcoSearchField v-model="q" placeholder="Search requests, owners, or destinations"
  label="Search requests" @search="(v) => (searched = v)" />
```

React (react-ecosphere):

```tsx
const [q, setQ] = useState("");
const [searched, setSearched] = useState("");

<EcoSearchField value={q} onChange={setQ} placeholder="Search requests, owners, or destinations"
  label="Search requests" onSearch={setSearched} />
```

## Finder

Sits inside a toolbar and carries its own filter button.

Vue (vue-ecosphere):

```vue
<EcoSearchField v-model="f" variant="finder" placeholder="Filter requests"
  label="Filter requests" filter-label="Filter requests" :filter-active="filterOn"
  @filter="filterOn = !filterOn" />
```

React (react-ecosphere):

```tsx
const [f, setF] = useState("");
const [filterOn, setFilterOn] = useState(false);

<EcoSearchField value={f} onChange={setF} variant="finder" placeholder="Filter requests"
  label="Filter requests" filterLabel="Filter requests" filterActive={filterOn}
  onFilter={() => setFilterOn((on) => !on)} />
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string` | "" | The query. The clear button shows only while it has a value (has-value). |
| `variant` | `"search" \| "finder"` | "search" | Full-width page bar, or the compact toolbar finder. |
| `placeholder` | `string` | — | What can be searched. |
| `label` | `string` | — | Accessible name; falls back to the placeholder. |
| `clearLabel` | `string` | "Clear search" | Name and tooltip of the clear button. |
| `filter` | `boolean` | true | Finder only: show the filter button (filb). |
| `filterActive / filterOpen` | `boolean` | false | Finder only: a filter is applied (is-on) / its menu is open. |
| `filterLabel` | `string` | "Filter" | Accessible name of the filter button. |
| `@search` | `(value: string) => void` | — | Enter in the field. |
| `@clear / @filter` | `() => void` | — | Clear button (or Escape) / filter button. |
| `#filter` | `slot` | — | Replace the filter button, e.g. with a menu trigger. |
| `attributes` | `id, role, aria-*, listeners` | — | Go to the <input> (class and style stay on the wrapper), so it can be a combobox's input. A keydown handler you pass runs first; preventDefault() keeps Enter or Escape for you. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onChange` | `string` | "" | The query. The clear button shows only while it has a value (has-value). |
| `variant` | `"search" \| "finder"` | "search" | Full-width page bar, or the compact toolbar finder. |
| `placeholder` | `string` | — | What can be searched. |
| `label` | `string` | — | Accessible name; falls back to the placeholder. |
| `clearLabel` | `string` | "Clear search" | Name and tooltip of the clear button. |
| `filter` | `boolean` | true | Finder only: show the filter button (filb). |
| `filterActive / filterOpen` | `boolean` | false | Finder only: a filter is applied (is-on) / its menu is open. |
| `filterLabel` | `string` | "Filter" | Accessible name of the filter button. |
| `onSearch` | `(value: string) => void` | — | Enter in the field. |
| `onClear / onFilter` | `() => void` | — | Clear button (or Escape) / filter button. |
| `filterButton` | `ReactNode` | — | Replace the filter button, e.g. with a menu trigger. |
| `attributes` | `id, role, aria-*, listeners` | — | Go to the <input> (class and style stay on the wrapper), so it can be a combobox's input. A keydown handler you pass runs first; preventDefault() keeps Enter or Escape for you. |
