Skip to content

Autocomplete

useAutocomplete keeps selected resources available even if they are absent from the active search query.

ts
const selectedUserIds = ref<string[]>([]);
const users = useAutocomplete({
  api,
  endpoint: 'users',
  currentValue: selectedUserIds,
  query: computed(() => ({ perPage: 20 })),
  identityKey: 'id',
});

Selected and searched results are deduplicated by identityKey. Use itemDisabled when the consumer must annotate options without changing the server response.

OptionDefaultPurpose
query{}Reactive request for search results.
currentValueno selected requestOne identity or an array of identities to keep loaded.
identityKeyidProperty used for the selected-resource condition and deduplication.
itemDisablednoneProduces a derived disabled boolean per returned item.
immediatetrueSet to false and call initialize() yourself.

initialize() and refresh() load selected resources and query results concurrently. loadCurrentItems() and loadItems() are available when the UI needs more granular control. Empty, null, or undefined selections do not issue the selected-resource request.

Released under the MIT License.