Skip to content

Search documentation

Search guides, examples, and component APIs.

Quick links
↑↓ NavigateEnter OpenEsc Close
Get started

Documentation navigation

Components / Forms

SearchInput

A native search field with a localized clear action.

Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.

Interactive showcase

Install

Run in your project
bunx --bun @getweini/cli@latest add search-input

Start with this example

Import the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.

Vue
<script setup lang="ts">
import { ref } from 'vue'
import SearchInput from './components/ui/search-input/SearchInput.vue'

const query = ref('')
const messages = { clear: 'Clear search' }
function submitSearch() {
  console.log(query.value)
}
</script>

<template>
  <label for="site-search">Search</label>
  <SearchInput
    id="site-search"
    v-model="query"
    name="query"
    :messages="messages"
    @search="submitSearch"
  />
</template>

The native type="search" input receives native attributes and events. Escape and the clear button empty the model while retaining focus; disabled and readonly fields cannot be cleared.

When to use it

Site search

Submit a query with the browser-native search control.

Live filtering

Filter a local list as the model changes and let users clear it quickly.

More examples

Search form

The search event can trigger a query.

Search form
<script setup lang="ts">
import { ref } from 'vue'
import SearchInput from './components/ui/search-input/SearchInput.vue'

const query = ref('')
const messages = { clear: 'Clear search' }
function submitSearch() {
  console.log(query.value)
}
</script>
<template>
  <label for="site-search">Search documentation</label>
  <SearchInput
    id="site-search"
    v-model="query"
    name="query"
    :messages="messages"
    @search="submitSearch"
  />
</template>

Filter names

A computed list responds to the native input model.

Filter names
<script setup lang="ts">
import { computed, ref } from 'vue'
import SearchInput from './components/ui/search-input/SearchInput.vue'

const query = ref('')
const names = ['Ada', 'Grace', 'Linus']
const results = computed(() =>
  names.filter((name) => name.toLowerCase().includes(query.value.toLowerCase())),
)
const messages = { clear: 'Clear name filter' }
</script>
<template>
  <label for="name-filter">Filter names</label>
  <SearchInput id="name-filter" v-model="query" :messages="messages" />
  <ul>
    <li v-for="name in results" :key="name">{{ name }}</li>
  </ul>
</template>

Complete API

Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.

SearchInput

Complete API for SearchInput
NameType or signatureDefaultWhat it does
rootClasspropClassValueNot setClasses applied to the outer component wrapper.
rootStylepropStyleValueNot setStyles applied to the outer component wrapper.
sizepropControlSize | undefined"md"Choose the visual size. Medium is the usual default where available.
invalidpropboolean | undefinedNot setShow the invalid state; also provide a visible error message.
disabledpropboolean | undefinedNot setPrevent interaction and show the disabled state.
readonlypropboolean | undefinedNot setShow the value while preventing edits.
messagespropSearchInputMessagesRequiredSupply the text this component displays for its built-in actions and states.
modelValuemodelstring | undefinedNot setCurrent value. Use v-model to keep it in sync with your page.
modelModifierspropPartial<Record<"trim" | "lazy", true>> | undefinedNot setControls the model modifiers behavior of SearchInput.
clearevent[]—Emitted when the user clears the value.
update:modelValueevent[value: string | undefined]—Requests a new model value from the parent.
errorslot{ message: string; messages: string[]; }OptionalContent for the error area of SearchInput.
elementexposedHTMLInputElement | null—Reference to the underlying HTML element.
focusexposed() => void | undefined—Move keyboard focus to this control.
clearexposed() => void—Access clear from a component template ref.
Public type definitions
Public types
// packages/frameworks/vue/components/search-input/types.ts
// ------- IMPORTS -------

import type { ControlSize } from '@getweini/vue/types'
import type { HTMLAttributes } from 'vue'

// ------- TYPES -------

export interface SearchInputMessages {
  clear: string
}

export interface SearchInputProps {
  rootClass?: HTMLAttributes['class']
  rootStyle?: HTMLAttributes['style']
  size?: ControlSize
  invalid?: boolean
  disabled?: boolean
  readonly?: boolean
  messages: SearchInputMessages
}


// packages/frameworks/vue/dist/types/index.d.ts
export type { ButtonOptions, ButtonProps } from './button';
export type ControlSize = 'sm' | 'md' | 'lg';
export interface SelectOption<T = unknown> {
    label: string;
    value: T;
    disabled?: boolean;
}
/** Application-owned copy. Bind translated strings reactively when the locale changes. */
export interface ListboxMessages {
    /** Popup name when no aria-label or aria-labelledby is supplied. */
    listboxLabel: string;
    empty: string;
    clearSelection: string;
}
export interface ListboxProps<T> {
    options: readonly SelectOption<T>[];
    messages: ListboxMessages;
    id?: string;
    disabled?: boolean;
    required?: boolean;
    invalid?: boolean;
    name?: string;
    form?: string;
    placeholder?: string;
    size?: ControlSize;
    clearable?: boolean;
    gap?: number;
    /** Supply stable equality for object values. Values must be unique. */
    by?: (a: T, b: T) => boolean;
    /** Required for meaningful form submission of object values. */
    serialize?: (value: T) => string;
}


// packages/frameworks/vue/dist/types/button.d.ts
import type { Component } from 'vue';
/** Options shared by button implementations across frameworks. */
export interface ButtonOptions<Variant extends string = string, Size extends string = string> {
    variant?: Variant;
    size?: Size;
    disabled?: boolean;
    loading?: boolean;
    type?: 'button' | 'submit' | 'reset';
}
/** Vue-specific target options extend the reusable button contract. */
export interface ButtonProps<Variant extends string = 'default' | 'secondary' | 'outline' | 'ghost' | 'destructive', Size extends string = 'sm' | 'md' | 'lg'> extends ButtonOptions<Variant, Size> {
    as?: 'button' | 'a' | Component;
    asChild?: boolean;
}

Implementation notes

  • rootClass and rootStyle style the visible wrapper; native attributes belong to the input.
  • The model supports .trim and .lazy modifiers.
  • The clear action emits clear and native input/change events; Escape also clears.
  • Readonly and disabled fields cannot be cleared.

Accessibility and localization

  • Provide a visible label and localize the clear action through messages.

Source contract and editing guidance