useTypeahead
Match a list item from characters the user types. Characters within one second form a prefix, and a repeated letter moves to the next match.
Usage
useTypeahead searches a list you supply. It returns the match and leaves selection, menus, and filtering to you.
import { useTypeahead } from '@vuetify/v0'
const states = ['Alabama', 'Alaska', 'American Samoa', 'Arizona']
const { typeahead, reset } = useTypeahead(() => states, {
text: state => state,
duration: 1000,
})
typeahead('a') // { item: 'Alabama', index: 0 }
typeahead('m') // { item: 'American Samoa', index: 2 }
reset()Architecture
Each call restarts a one-second timer. When the timer fires, the buffer is cleared. reset() clears it immediately.
Options
| Option | Type | Default | Description |
|---|---|---|---|
text | (item: T) => string | — | Text used for prefix matching. Read on every key. Not trimmed. |
duration | MaybeRefOrGetter<number> | 1000 | Inactivity window, in milliseconds, before the buffer clears. |
Examples
- ALAlabama
- AKAlaska
- ASAmerican Samoa
- AZArizona
Match none
Selected
None
Catalog
- 1Apricot
- 2Avocado
- 3Banana
- 4Blackberry
FAQ
No. typeahead returns { item, index } or undefined. Updating a model, moving highlight, and opening a list are the caller’s job.
No. Whatever items returns is searched, in that order. Filter the list before passing it if some entries should not match.
If the last two buffered characters are the same and that prefix misses, the extra character is dropped and the search continues at the next index. An item that actually starts with the doubled prefix, such as aa on Aardvark, stays a prefix match and does not cycle.
After duration milliseconds without another character (one second by default), or when you call reset(). Arrow keys and closing a list do not clear it unless you reset it yourself.