Autocomplete / Suggest

The suggest control adds type-ahead suggestions to any text input. Feed it a static JSON array or point it at a remote JSON endpoint — results filter as the user types, wired with useSuggest. Alias: data-vd-autocomplete.

Basic — Static JSON Array
EU Capitals
Minimum Characters (2)
Alias: data-vd-autocomplete
API Reference

Wiring

import { ref } from 'vue';
import { useSuggest } from "@vanduo-oss/vd3";

const root = ref<HTMLElement | null>(null);
useSuggest(root);   // wires [data-vd-suggest] inside root; cleanup on unmount

// react to a selection
root.value?.addEventListener('suggest:select', (e) => {
  console.log(e.detail.value);
});

CSS Classes

ClassDescription
.vd-suggest-wrapperAuto-generated wrapper around the input; positions the dropdown list
.vd-suggest-listThe dropdown <ul> containing suggestion items
.vd-suggest-itemIndividual suggestion <li> inside the list
.vd-suggest-matchWraps the matched substring within each suggestion item (bold highlight)
.vd-suggest-emptyShown when no results match the current query

Data Attributes

AttributeDescription
data-vd-suggestActivates the component. Optionally holds an inline JSON array of strings (or { label, text, value } objects)
data-vd-suggest-urlURL to fetch suggestions from a JSON endpoint (same-origin by default). Overrides inline data
data-vd-suggest-allowlistComma-separated list of allowed external origins for data-vd-suggest-url (e.g. "https://api.example.com")
data-vd-suggest-min-charsMinimum characters before the dropdown appears (default: 1)
data-vd-autocompleteAlias for data-vd-suggest — works identically

Composable API

SymbolDescription
useSuggest(root)Composable — attaches type-ahead suggestions to every [data-vd-suggest] / [data-vd-autocomplete] input inside the root ref. Call once in setup().
(automatic cleanup)The dropdown, debounce timer and listeners are removed on component unmount.

Events

EventDescription
suggest:selectFired on the input when the user picks a suggestion. event.detail contains { value, item, index }
Accessibility
  • The input receives role="combobox" and aria-autocomplete="list"
  • The suggestion list has role="listbox"; each item has role="option"
  • aria-expanded toggles true/false as the dropdown opens and closes
  • aria-activedescendant tracks the currently highlighted option for screen readers
  • ↑ / ↓ arrow keys navigate the list; Enter selects; Escape closes
  • Focus returns to the input after selection, preserving natural tab order