Search bar

Filters a list or page by text, with a clear button once there is a query.

Refined portVue source: WildSearchBar.vueStorybook story: Forms/Search Bar

Try it

Type into it, then clear it with the ×. Clearing puts focus back in the field.

Size
Disabled
<WildSearchBar
  v-model="query"
  size="md"
  placeholder="Search sites"
/>

When to use

  • Use it to filter a list or a page by text.
  • Pass onClear so people can empty the query in one press.
Don’t use it
  • For a value that’s saved with a form. Use a text input.

Anatomy

A magnifier, the text field and a clear button, in one frame.

<WildSearchBar v-model="query"
  placeholder="Search sites" />
The clear button appears only once there’s a query to clear.

Sizes

Three heights: 36, 40 and 44px. The default is md.

sm
md
lg

States

The frame is the text input’s, so a search bar and a text field focus the same way on one form.

rest
hover
focus
error
disabled

Accessibility

The field is named by ariaLabel, or by its placeholder when there’s none. The clear button is named “Clear search”.

KeyWhat it does
TabMoves to the field, then to the clear button.
Enter / SpaceOn the clear button, empties the query and returns focus to the field.

Props

PropTypeDefaultDescription
valuestring—The query.
onChange(value: string) => void—Called on every keystroke.
onClear() => void—Shows the clear button while there’s a query.
placeholderstring'Search'Shown while empty. Also the fallback name.
size'sm' | 'md' | 'lg''md'Height: 36, 40 or 44px.
errorbooleanfalseRed frame.
disabledbooleanfalseBlocks typing and dims the frame.
trailingReactNode—A slot at the end, such as a shortcut hint.
widthnumber | string'100%'Frame width.
ariaLabelstring—Accessible name for the field.
autoFocusbooleanfalseFocuses the field on mount.
state'rest' | 'hover' | 'focus'—Forces a frame, for static examples.

Tokens

TokenValueWhere it lands
--radius-field10pxThe frame.
--global-neutral-grey-800#ADACB0Frame on hover.
--global-blue-1000#1877F2Frame on focus.
--color-error#E12121Frame on error.
--global-neutral-grey-900#7F7D83Magnifier, and the clear button at rest.
--global-neutral-grey-400 / -1100#ECECED / #2D2B32Clear button ground and ink on hover.
--size-icon-sm16pxThe magnifier.