Form
AutoComplete
A text box that suggests as you type, with suggestions supplied by your app, single or multiple values as chips, and a button for the whole list.
WAI-ARIA tested
Import
main.ts
import { AutoComplete } from '@vitral/vue';Basic
Value: null
Dropdown and forced selection
Multiple
With a mask
The query is typed into a mask, and with `unmask` it is only the digits. A chosen suggestion shows its label; typing again reads it into the mask.
Value: null
Groups and templates
Plain strings, sizes and states
API
Read from packages/vue/src/components/AutoComplete/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| suggestions | any[] | What the list offers for the current query; the app sets it in answer to `complete`. |
| optionLabel | string | Field (dotted path) holding a suggestion's text. Without it, suggestions are shown as they are. |
| optionDisabled | string | — |
| optionGroupLabel | string | Turns `suggestions` into groups: this field is each group's label… |
| optionGroupChildren | string | …and this one its suggestions. Defaults to `items`. |
| dataKey | string | Compare object values by this field instead of structurally. |
| multiple | boolean | v-model becomes an array, shown as chips in the field. |
| dropdown | boolean | Adds a button that asks for the whole list. |
| dropdownMode | 'blank' | 'current' | What the button asks for: every suggestion (`'blank'`, the default) or those matching the current text. |
| forceSelection | boolean | Only a chosen suggestion may stay in the box; other text is cleared when it loses focus. |
| delay | number | Milliseconds to wait after typing before asking. Defaults to 300. |
| minLength | number | Characters to type before asking. Defaults to 1. |
| completeOnFocus | boolean | Ask as soon as the box takes focus. |
| autoOptionFocus | boolean | Put the first suggestion in focus when the list opens, so Enter takes it. |
| showClear | boolean | Shows a clear button while there is a value. |
| loading | boolean | Shows a spinner, for while the app is searching. |
| showEmptyMessage | boolean | Say so when nothing matches, rather than keeping the list closed. Defaults to true. |
| emptySearchMessage | string | — |
| size | Size | — |
| variant | InputVariant | Defaults to the plugin's `inputVariant`. |
| invalid | boolean | — |
| disabled | boolean | — |
| readonly | boolean | — |
| fluid | boolean | — |
| placement | OverlayPlacement | — |
| appendTo | string | `'body'` (the default), `'self'` to render in place, or a selector. |
| mask | MaskProp | The pattern: `9` takes a digit, `a` a letter, `*` either; anything after `?` is optional; every other character is typed for the reader. A list of patterns lets the value take more than one shape: the first with room for what has been typed is shown, so `['999.999.999-99', '99.999.999/9999-99']` is a CPF that turns into a CNPJ at the twelfth digit, and back again when one is deleted. A function receives the characters typed so far, without literals, and returns the pattern to show. An object carries the pattern with its settings, so one mask can be defined once and passed to any field. |
| slotChar | string | What an empty slot shows: one character, or a string as long as the mask (`'mm/dd/yyyy'`). Defaults to `_`. |
| autoClear | boolean | Clear an unfinished value when the box loses focus. Defaults to true. |
| unmask | boolean | v-model receives only the typed characters, without the literals. |
| definitions | MaskDefinitions | Extra slot characters, each with the characters it accepts. |
| scrollbar | ScrollbarMode | The bars of the boxes this component scrolls inside — `'hover'`, `'always'` or `'native'`. The application's `scrollbar` option by default, which is `'hover'`. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| complete | event: AutoCompleteCompleteEvent | Asks the app for the suggestions matching `query`. |
| option-select | event: AutoCompleteOptionEvent | — |
| option-unselect | event: AutoCompleteOptionEvent | — |
| dropdown-click | event: AutoCompleteCompleteEvent | — |
| clear | — | — |
| show | — | — |
| hide | — | — |
| focus | event: FocusEvent | — |
| blur | event: FocusEvent | — |
Slots
| Name | Slot props | Description |
|---|---|---|
| option | (props: { option: unknown; index: number; selected: boolean; focused: boolean }) | — |
| optiongroup | (props: { group: unknown }) | — |
| chip | (props: { value: unknown; label: string; remove: (event: Event) => void }) | A chip's content in multiple mode. |
| header | — | — |
| footer | — | — |
| empty | — | — |
| dropdownicon | — | — |