Autocomplete
The Autocomplete input component allows you to search through a list of options. It is an advanced input that provides suggestions as the user types. Based on the Dropdown component, the component implements the W3C ARIA APG Combobox Pattern. Use it with the Field component to access all functionalities.
Examples
Base
Selection
The autocomplete input can only contain one item at a time. For the multiple selection version, see the Taginput component.
Options
The options
prop can accept several different formats of values:
- An array of primitives
['A', 'B', 'C']
- An object literal with key-value pairs
{ a: 'A', b: 'B', c: 'C' }
- An array of objects with
label
andvalue
properties - Grouped options by adding additional
options
to the option object.
Note
The options
prop works the same as the Select input component options
prop.
Slots
A header and a footer can be added to the options list by using the header
and footer
slots. The header and footer can be made clickable by adding the selectable-header
and selectable-footer
props. Clicking them will clear the input.
Infinite Scroll & Async Data
When check-scroll
prop is set, the component will emits the scroll-start
and scroll-end
events. These events can be used to load more options as needed. Consider adding backend-filtering
when manually updating options on input values changes.
Note
The autocomplete component does not have a default slot for defining options. The default slot is used to override the option element template.
Autocomplete component
Extended input that provide suggestions while the user types.
<o-autocomplete></o-autocomplete>
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
active | The active state of the dropdown, use v-model:active to make it two-way binding | boolean | - | false |
animation | Transition name to apply on dropdown list | string | - | From config: autocomplete: { |
autocomplete | Native options to use in HTML5 validation | string | - | From config: autocomplete: { |
backendFiltering | Options won't be filtered based on the input value on clientside | boolean | - | From config: autocomplete: { |
checkScroll | Makes the component check if list reached scroll start or end and emit scroll events | boolean | - | From config: autocomplete: { |
clearIcon | Icon name to be added on the clear button | string | - | From config: autocomplete: { |
clearOnSelect | Clear input text on select | boolean | - | From config: autocomplete: { |
clearable | Add a button/icon to clear the inputed text | boolean | - | From config: autocomplete: { |
customValidity | Custom HTML 5 validation error to set on the form control | string | ((currentValue: unknown, state: ValidityState) => string) | - | |
debounce | Number of milliseconds to delay before to emit input event | number | - | From config: autocomplete: { |
desktopModal | Dropdown content (items) are shown into a modal on desktop | boolean | - | From config: dropdown: { |
disabled | Same as native input disabled | boolean | - | false |
expanded | Makes input full width when inside a grouped or addon field | boolean | - | false |
filter | Function to filter the option based on the input value - default is label string comparison | ((option: unknown, value: string) => boolean) | - | |
icon | Icon to be shown | string | - | From config: autocomplete: { |
iconClickable | Makes the icon clickable | boolean | - | false |
iconPack | Icon pack to use | string | mdi , fa , fas and any other custom icon pack | From config: autocomplete: { |
iconRight | Icon to be added on the right side | string | - | From config: autocomplete: { |
iconRightClickable | Make the icon right clickable | boolean | - | false |
iconRightVariant | Variant of right icon | string | - | |
input | The value of the inner input, use v-model:input to make it two-way binding | string | - | "" |
itemTag | Menu item tag name | DynamicComponent | - | From config: autocomplete: { |
keepFirst | The first option will always be focused (easier to just hit enter or tab) | boolean | - | From config: autocomplete: { |
keepOpen | Keep open dropdown list after select | boolean | - | From config: autocomplete: { |
maxHeight | Max height of dropdown content | number | string | - | From config: autocomplete: { |
maxlength | Same as native maxlength, plus character counter | number | string | - | |
menuTag | Menu tag name | DynamicComponent | - | From config: autocomplete: { |
mobileModal | Dropdown content (items) are shown into a modal on mobile | boolean | - | From config: autocomplete: { |
v-model | The selected option value, use v-model to make it two-way binding | string|number|object | - | |
openOnFocus | Open dropdown list on focus | boolean | - | From config: autocomplete: { |
options | Autocomplete options | OptionsPropWithGroups<unknown> | - | |
override | Override existing theme classes completely | boolean | - | |
placeholder | Input placeholder | string | - | |
position | Position of the dropdown | "auto" | "bottom" | "top" | auto , top , bottom | From config: autocomplete: { |
rounded | Makes the element rounded | boolean | - | false |
selectOnClose | Trigger the select event for focused option when drodpown got closed | boolean | - | false |
selectableFooter | Allows the footer in the autocomplete to be selectable | boolean | - | false |
selectableHeader | Allows the header in the autocomplete to be selectable | boolean | - | false |
size | Size of the input control | string | small , medium , large | From config: autocomplete: { |
statusIcon | Show status icon using field and variant prop | boolean | - | From config: { |
teleport | Append the component to another part of the DOM. Set true to append the component to the body.In addition, any CSS selector string or an actual DOM node can be used. | boolean | object | string | - | From config: autocomplete: { |
type | Input type | string | - | "text" |
useHtml5Validation | Enable HTML 5 native validation | boolean | - | From config: { |
Events
Event name | Properties | Description |
---|---|---|
update:model-value | value T - updated modelValue prop | modelValue prop two-way binding |
update:input | value string - updated input prop | input prop two-way binding |
update:active | value boolean - updated active prop | active prop two-way binding |
input | value string - input valueevent Event - native event | on input change event |
select | value T - selected value | selected element changed event |
select-header | header is selected | |
select-footer | footer is selected | |
focus | event Event - native event | on input focus event |
blur | event Event - native event | on input blur event |
invalid | event Event - native event | on input invalid event |
icon-click | event Event - native event | on icon click event |
icon-right-click | event Event - native event | on icon right click event |
scroll-start | the list inside the dropdown reached the start | |
scroll-end | the list inside the dropdown reached it's end |
Slots
Name | Description | Bindings |
---|---|---|
header | Define an additional header | |
group | Override the option group | group object - options groupindex number - option index |
default | Override the select option | option object - option objectvalue unknown - option valueindex number - option index |
empty | Define content for empty state | |
footer | Define an additional footer |
Class Inspector
Class prop | Description | Props | Suffixes | |
---|---|---|---|---|
rootClass | Class of the root element. | |||
itemClass | Class of the menu items. | |||
itemGroupTitleClass | Class of the menu items group title. | |||
itemEmptyClass | Class of the empty menu placeholder item. | |||
itemHeaderClass | Class of the menu header item. | |||
itemFooterClass | Class of the menu footer item. | |||
inputClasses | Classes to apply on the internal input component. More details here. |
Sass variables
Current theme ➜ Oruga
SASS Variable | Default |
---|---|
$autocomplete-item-hover-background-color | #f5f5f5 |
See ➜ 📄 Full scss file
Current theme ➜ Bulma
The theme does not have any custom variables for this component.
Current theme ➜ Bootstrap
SASS Variable | Default |
---|---|
$autocomplete-menu-max-height | 200px |
See ➜ 📄 Full scss file