Local options · recent selections · default appearance
Find a fruit
Choose from 30 fruits in English. The last three selections are saved in this browser and shown when the field is empty. With recent suggestions open, activate the chevron to show every fruit; it points up while the full list is open. The field uses the component's default size and appearance, with the active theme's standard colors.
Nothing selected
HTML
<lgs1920-autocomplete id="local-autocomplete" label="Fruit" name="fruit" with-clear>
<wa-icon slot="start" name="magnifying-glass" aria-hidden="true"></wa-icon>
</lgs1920-autocomplete>
JavaScript
const field = document.querySelector('#local-autocomplete')
field.options = [
{value: 'apple', label: 'Apple', category: 'Pome fruit'},
{value: 'apricot', label: 'Apricot', category: 'Stone fruit'},
{value: 'avocado', label: 'Avocado', category: 'Tropical fruit'},
{value: 'banana', label: 'Banana', category: 'Tropical fruit'},
{value: 'blackberry', label: 'Blackberry', category: 'Berry'},
{value: 'blueberry', label: 'Blueberry', category: 'Berry'},
{value: 'cantaloupe', label: 'Cantaloupe', category: 'Melon'},
{value: 'cherry', label: 'Cherry', category: 'Stone fruit'},
{value: 'coconut', label: 'Coconut', category: 'Tropical fruit'},
{value: 'cranberry', label: 'Cranberry', category: 'Berry'},
{value: 'dragon-fruit', label: 'Dragon fruit', category: 'Tropical fruit'},
{value: 'fig', label: 'Fig', category: 'Tropical fruit'},
{value: 'grape', label: 'Grape', category: 'Berry'},
{value: 'grapefruit', label: 'Grapefruit', category: 'Citrus fruit'},
{value: 'guava', label: 'Guava', category: 'Tropical fruit'},
{value: 'kiwi', label: 'Kiwi', category: 'Tropical fruit'},
{value: 'lemon', label: 'Lemon', category: 'Citrus fruit'},
{value: 'lime', label: 'Lime', category: 'Citrus fruit'},
{value: 'mango', label: 'Mango', category: 'Tropical fruit'},
{value: 'nectarine', label: 'Nectarine', category: 'Stone fruit'},
{value: 'orange', label: 'Orange', category: 'Citrus fruit'},
{value: 'papaya', label: 'Papaya', category: 'Tropical fruit'},
{value: 'peach', label: 'Peach', category: 'Stone fruit'},
{value: 'pear', label: 'Pear', category: 'Pome fruit'},
{value: 'pineapple', label: 'Pineapple', category: 'Tropical fruit'},
{value: 'plum', label: 'Plum', category: 'Stone fruit'},
{value: 'pomegranate', label: 'Pomegranate', category: 'Pome fruit'},
{value: 'raspberry', label: 'Raspberry', category: 'Berry'},
{value: 'strawberry', label: 'Strawberry', category: 'Berry'},
{value: 'watermelon', label: 'Watermelon', category: 'Melon'},
]
field.persistence = {id: 'fruit-search-demo', limit: 3}
field.addEventListener('wa-select', event => {
console.log(event.detail.value, event.detail.option.category)
})