Skip to content
bahtuiv0.6.0

<baht-typeahead>

Text input with suggestions. The text is the value; pick a suggestion and the input shows its label. Static options filtered client-side (prefix matches first) or an async fetcher(term); typing is debounced.

Static options

free-text="false" makes the text a filter only — blur reverts to the last pick.

<baht-typeahead label="Country" placeholder="Start typing…"></baht-typeahead>

<script>
  const el = document.querySelector('baht-typeahead');
  el.options = [
  { key: 'th', label: 'Thailand' },
  { key: 'tw', label: 'Taiwan' },
  { key: 'nl', label: 'Netherlands', sub: 'EU' },
  ];
  el.addEventListener('baht-change', (e) => console.log(e.detail)); // { value, option }
  el.addEventListener('baht-select', (e) => console.log(e.detail.option.key));
</script>

Async fetcher

<baht-typeahead label="City" min-chars="2"></baht-typeahead>

<script>
  const el = document.querySelector('baht-typeahead');
  el.fetcher = (term) => api.searchCities(term); // Promise<{ key, label, sub? }[]>
</script>
NameTypeDefaultDescription
labelstring'Search'Accessible name
valuestring''The text (controlled)
placeholderstring''Input placeholder
disabledbooleanfalseDisabled
invalidbooleanfalseError styling
optionsJSTypeaheadOption[][]Static suggestions { key, label, sub? }, filtered here
fetcherJS((term: string) => Promise<TypeaheadOption[]>) | nullnullAsync suggestions; overrides options
debouncenumber150Quiet ms before emit/fetch
min-charsnumber1Chars before suggesting
max-itemsnumber8Suggestions shown
free-textbooleantruefalse = only picked options count; blur reverts
autocompletestring'off'HTML autocomplete token forwarded to the input ('off' keeps the browser's own list away).
EventdetailDescription
nameCustomEvent
baht-change{ value, option }Text changed (debounced) or a suggestion picked (option set)
baht-select{ option }A suggestion was picked