rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.25k stars 175 forks source link

Blue square on second attempt to select an item #666

Closed fedeperin closed 4 months ago

fedeperin commented 5 months ago

Video of the issue:

Video

I'm having a problem, the second time that I try to select an item the options change it's background to a blue one and they are no more selectable. The code is the following:

<script>
    import Select from 'svelte-select'
    const items = [
        {
            label: 'Cats',
            name: 'cats'
        },
        {
            label: 'Dogs',
            name: 'dogs'
        },
        {
            label: 'Rats',
            name: 'rats'
        }
    ]
    let value = items[0].label
</script>
<Select
{items}
clearable={ false }
bind:value
/>
rob-balfre commented 5 months ago

<Select itemId="name" ... >

jamesscottbrown commented 5 months ago

More explicitly:

Unless you provide an alternative field name as the itemId prop, svelte-select assumes that the id of each item is contained in a field called value. Once an item has been selected, any items with the same id will be highlighted. In your case, selecting any item hghlights all of them: the field is missing from all the items, so they are all treated as having the same id (undefined).

fedeperin commented 4 months ago

Thanks, my problem got solved adding the itemId.