
The typeahead function is used to search for items in a list, based on user input. When a match is found, the match event is emitted.
import { typeahead } from '@aracna/core';
const key = 'fruits';
const input = document.createElement('input');
const items = ['apple', 'banana', 'cherry'];
input.addEventListener('keydown', (event) => {
event.preventDefault();
event.stopPropagation();
typeahead(key, event.key)
.setItems(items)
.setListeners([])
.setPredicate((item, query) => item.startsWith(query))
.on('match', (item) => console.log('match', item));
});
document.getElementById('root').append(input);