Skip to content

Autocomplete API Reference

Props

PropTypeDefaultDescription
itemsArray[]Array of items to display in the autocomplete dropdown
modelValueString/Number/Array/ObjectnullSelected value(s) for v-model binding
itemTextString'text'Property name for item display text
itemValueString'value'Property name for item value
itemDisabledString'disabled'Property name for item disabled state
multipleBooleanfalseEnable multiple item selection
filterFunctionFunctionnullCustom filter function (item, searchText) => boolean
selectedOnTopBooleanfalseShow selected items at the top of the list
placementString'bottom'Dropdown placement relative to trigger. Options: 'top', 'bottom', 'left', 'right'
offsetArray[0, 0.125]Offset from trigger element [x, y] in rem units
menuWidthString/NumbernullExplicit dropdown width (matches trigger width when null)
matchTriggerWidthBooleantrueMatch dropdown width to trigger width
placeholderString''Placeholder text for the input field
disabledBooleanfalseDisable the autocomplete input
loadingBooleanfalseShow loading spinner in input and dropdown
clearableBooleanfalseShow clear button when there's a selection or search text
readonlyBooleanfalseMake the input field readonly

Events

EventPayloadDescription
update:modelValuevalueEmitted when selection changes (for v-model)
changevalueEmitted when selection changes
selectitem, valueEmitted when an item is selected
removeitem, valueEmitted when an item is removed (multiple mode)
searchsearchTextEmitted when search text changes

Slots

SlotPropsDescription
no-data-Custom content when no items match the search or no items are available

Methods

MethodDescription
focus()Focus the input field
blur()Blur the input field
openMenu()Open the dropdown menu
closeMenu()Close the dropdown menu
search(value)Set the search text programmatically

Basic Usage

vue
<template>
  <OAutoComplete
    v-model="selectedValue"
    :items="items"
    placeholder="Search and select..."
    @select="handleSelect"
  />
</template>

<script setup>
import { ref } from "vue";

const selectedValue = ref(null);
const items = ref([
  { text: "Option 1", value: "option1" },
  { text: "Option 2", value: "option2" },
  { text: "Option 3", value: "option3" },
]);

const handleSelect = (item, value) => {
  console.log("Selected:", item, value);
};
</script>

Item Structure

Items can be provided in different formats:

javascript
const items = [
  { text: "Apple", value: "apple", disabled: false },
  { text: "Banana", value: "banana" },
  { text: "Orange", value: "orange" },
];

Simple Array Format

javascript
const items = ["Apple", "Banana", "Orange"];
// text and value will be the same string

Custom Property Names

vue
<OAutoComplete
  v-model="selected"
  :items="items"
  item-text="name"
  item-value="id"
  item-disabled="isDisabled"
/>

Filter Function

You can provide a custom filter function for advanced filtering:

vue
<template>
  <OAutoComplete
    v-model="selected"
    :items="items"
    :filter-function="customFilter"
  />
</template>

<script setup>
const customFilter = (item, searchText) => {
  // Custom filtering logic
  const text = item.name.toLowerCase();
  const search = searchText.toLowerCase();
  
  // Example: Match in multiple fields
  return text.includes(search) || 
         item.description?.toLowerCase().includes(search);
};
</script>

Multiple Selection

vue
<template>
  <OAutoComplete
    v-model="selectedValues"
    :items="items"
    :multiple="true"
    placeholder="Select multiple items..."
  />
</template>

<script setup>
import { ref } from "vue";

const selectedValues = ref([]);
const items = ref([
  { text: "Vue.js", value: "vue" },
  { text: "React", value: "react" },
  { text: "Angular", value: "angular" },
]);
</script>