Skip to content

Autocomplete

Input field with dropdown suggestion list. Follows the ARIA combobox pattern for full keyboard and screen reader support.


Demo

Autocomplete (static data)

Prøv at skrive 'banan' eller 'æble'


When to use

  • User needs to select from a large set of options (more than 15)
  • Options can be filtered by typing
  • Free text input combined with suggestions (e.g. search, address lookup)

When not to use

  • 5–15 fixed options — use Select
  • Fewer than 5 options — use radio buttons
  • Multiple selections — use checkboxes

Installation

bash
pnpm add @grundtone/vue

Usage

vue
<script setup>
  import { ref } from 'vue';
  const query = ref('');
  const suggestions = ref([]);

  function onSearch(q) {
    suggestions.value = myData.filter(item =>
      item.label.toLowerCase().includes(q.toLowerCase())
    );
  }
</script>

<template>
  <GTAutocomplete
    v-model="query"
    :suggestions="suggestions"
    label="Search"
    placeholder="Type to search..."
    @search="onSearch"
    @select="handleSelect"
  />
</template>

Props

PropTypeDefaultDescription
modelValuestring''Input text (v-model)
suggestionsAutocompleteSuggestion[][]Suggestion list
size'sm' | 'md' | 'lg''md'Size preset
placeholderstringPlaceholder text
labelstringVisible label
helpTextstringHelp text
errorTextstringError message
requiredbooleanfalseRequired field
disabledbooleanfalseDisabled state
loadingbooleanfalseShow loading indicator
minCharsnumber2Min chars before showing suggestions
noResultsTextstring'Ingen resultater'Empty state text

Events

EventPayloadDescription
update:modelValuestringInput text changed
searchstringDebounced search query
selectAutocompleteSuggestionSuggestion selected

Accessibility

  • role="combobox" on input with aria-expanded, aria-controls, aria-activedescendant
  • role="listbox" on dropdown, role="option" on each item
  • Keyboard: Arrow up/down navigates, Enter selects, Escape closes
  • autocomplete="off" to prevent browser interference
  • Loading and empty states are role="presentation"

Design system

The CSS-only version is documented in the Design System — Autocomplete reference.