Skip to content

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 and value 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.

html
<o-autocomplete></o-autocomplete>

Props

Prop nameDescriptionTypeValuesDefault
activeThe active state of the dropdown, use v-model:active to make it two-way bindingboolean-false
animationTransition name to apply on dropdown liststring-
From config:
autocomplete: {
  animation: "fade"
}
autocompleteNative options to use in HTML5 validationstring-
From config:
autocomplete: {
  autocomplete: "off"
}
backendFilteringOptions won't be filtered based on the input value on clientsideboolean-
From config:
autocomplete: {
  backendFiltering: false
}
checkScrollMakes the component check if list reached scroll start or end and emit scroll eventsboolean-
From config:
autocomplete: {
  checkScroll: false
}
clearIconIcon name to be added on the clear buttonstring-
From config:
autocomplete: {
  clearIcon: "close-circle"
}
clearOnSelectClear input text on selectboolean-
From config:
autocomplete: {
  clearOnSelect: false
}
clearableAdd a button/icon to clear the inputed textboolean-
From config:
autocomplete: {
  clearable: false
}
customValidityCustom HTML 5 validation error to set on the form controlstring | ((currentValue: unknown, state: ValidityState) => string)-
debounceNumber of milliseconds to delay before to emit input eventnumber-
From config:
autocomplete: {
  debounce: 400
}
desktopModalDropdown content (items) are shown into a modal on desktopboolean-
From config:
dropdown: {
  desktopModal: false
}
disabledSame as native input disabledboolean-false
expandedMakes input full width when inside a grouped or addon fieldboolean-false
filterFunction to filter the option based on the input value - default is label string comparison((option: unknown, value: string) => boolean)-
iconIcon to be shownstring-
From config:
autocomplete: {
  icon: undefined
}
iconClickableMakes the icon clickableboolean-false
iconPackIcon pack to usestringmdi, fa, fas and any other custom icon pack
From config:
autocomplete: {
  iconPack: undefined
}
iconRightIcon to be added on the right sidestring-
From config:
autocomplete: {
  iconRight: undefined
}
iconRightClickableMake the icon right clickableboolean-false
iconRightVariantVariant of right iconstring-
inputThe value of the inner input, use v-model:input to make it two-way bindingstring-""
itemTagMenu item tag nameDynamicComponent-
From config:
autocomplete: {
  itemTag: "div"
}
keepFirstThe first option will always be focused (easier to just hit enter or tab)boolean-
From config:
autocomplete: {
  keepFirst: false
}
keepOpenKeep open dropdown list after selectboolean-
From config:
autocomplete: {
  keepOpen: false
}
maxHeightMax height of dropdown contentnumber | string-
From config:
autocomplete: {
  maxHeight: undefined
}
maxlengthSame as native maxlength, plus character counternumber | string-
menuTagMenu tag nameDynamicComponent-
From config:
autocomplete: {
  menuTag: "div"
}
mobileModalDropdown content (items) are shown into a modal on mobileboolean-
From config:
autocomplete: {
  mobileModal: false
}
v-modelThe selected option value, use v-model to make it two-way bindingstring|number|object-
openOnFocusOpen dropdown list on focusboolean-
From config:
autocomplete: {
  openOnFocus: false
}
optionsAutocomplete optionsOptionsPropWithGroups<unknown>-
overrideOverride existing theme classes completelyboolean-
placeholderInput placeholderstring-
positionPosition of the dropdown"auto" | "bottom" | "top"auto, top, bottom
From config:
autocomplete: {
  position: "auto"
}
roundedMakes the element roundedboolean-false
selectOnCloseTrigger the select event for focused option when drodpown got closedboolean-false
selectableFooterAllows the footer in the autocomplete to be selectableboolean-false
selectableHeaderAllows the header in the autocomplete to be selectableboolean-false
sizeSize of the input controlstringsmall, medium, large
From config:
autocomplete: {
  size: undefined
}
statusIconShow status icon using field and variant propboolean-
From config:
{
  statusIcon: true
}
teleportAppend 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: {
  teleport: false
}
typeInput typestring-"text"
useHtml5ValidationEnable HTML 5 native validationboolean-
From config:
{
  useHtml5Validation: true
}

Events

Event namePropertiesDescription
update:model-valuevalue T - updated modelValue propmodelValue prop two-way binding
update:inputvalue string - updated input propinput prop two-way binding
update:activevalue boolean - updated active propactive prop two-way binding
inputvalue string - input value
event Event - native event
on input change event
selectvalue T - selected valueselected element changed event
select-headerheader is selected
select-footerfooter is selected
focusevent Event - native eventon input focus event
blurevent Event - native eventon input blur event
invalidevent Event - native eventon input invalid event
icon-clickevent Event - native eventon icon click event
icon-right-clickevent Event - native eventon icon right click event
scroll-startthe list inside the dropdown reached the start
scroll-endthe list inside the dropdown reached it's end

Slots

NameDescriptionBindings
headerDefine an additional header
groupOverride the option groupgroup object - options group
index number - option index
defaultOverride the select optionoption object - option object
value unknown - option value
index number - option index
emptyDefine content for empty state
footerDefine an additional footer

Class Inspector

Classes applied to the element:
Class propDescriptionPropsSuffixes
rootClassClass of the root element.
itemClassClass of the menu items.
itemGroupTitleClassClass of the menu items group title.
itemEmptyClassClass of the empty menu placeholder item.
itemHeaderClassClass of the menu header item.
itemFooterClassClass of the menu footer item.
inputClassesClasses to apply on the internal input component. More details here.

Sass variables

Current theme ➜ Oruga

SASS VariableDefault
$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 VariableDefault
$autocomplete-menu-max-height200px

See ➜ 📄 Full scss file

Released under the MIT License.