Autocomplete

Autocomplete form component provides suggestions while you type. It is often used for tags and contacts input.

↘ bottom_right
Selected: [ ↘ bottom_right ]
Created: [ ]

<script>
    import { Autocomplete } from 'svelte-spectre'

    let predefined = [
            'top_left',
            'top_center',
            'top_right',
            'center_left',
            'center_center',
            'center_right',
            'bottom_left',
            'bottom_center',
            'bottom_right',
        ],
        groups = [
            '↖ top_left',
            '↑ top_center',
            '↗ top_right',
            '← center_left',
            '✛ center_center',
            '→ center_right',
            '↙ bottom_left',
            '↓ bottom_center',
            '↘ bottom_right',
        ],
        selected = []

    const groupsBy = (item) => {
        return groups.split(', ').find((g) => item.value.includes(g))
    }
</script>

<Autocomplete
    {predefined}
    bind:selected
    bind:created
    placeholder="type here"
    empty="No suggested"
    {groupBy}
/>
<small>Selected: [ {selected.map(s => s.label).join(', ')} ]</small>
<small>Created: [ {created.map(s => s.label).join(', ')} ]</small>
© 2022 — 2023 BASF SE

API Autocomplete

predefined: string | Item = []
Predefined values array input
type Item = { index: number; label: string; value?: any; group?: string; type?: Color; style?: string; }
selected: Item[] = []
Selected values array output
[]
created: Item[] = []
Created values array output
[]
groupBy: (item: Item) => item = undefined
Groupping condition – returns headers strings
groups headers
predictable: boolean = false
Open suggested values list only on search match
true | false
creatable: boolean = false
Can add to suggested list new values
true | false
placeholder: string = "type here"
Placeholder
any string
empty: string = "No suggested"
No suggested message
any string