huntabyte / cmdk-sv

cmdk, but for Svelte ✨
https://cmdk-sv.com
MIT License
470 stars 19 forks source link

bug: duplicate item id issue #48

Closed MentalGear closed 8 months ago

MentalGear commented 8 months ago

Thanks for this lib! Here's a small issue: Items with the same name are highlighted as being the same even though they have been given different ids.

https://github.com/huntabyte/cmdk-sv/assets/2837147/a9b529a1-909c-4971-8354-99d3663af7ce

huntabyte commented 8 months ago

IDs don't matter. The value prop should be unique for each item. See README's FAQ section.

MentalGear commented 8 months ago

Mh, using the value prop, value={String(Math.random())} will make cmd not render any values.

huntabyte commented 8 months ago

That's what is being filtered by. What the user is searching by should be passed as the value.

MentalGear commented 8 months ago

I was finally able to get this working with value and setting off the filter (seems strange to have it on by default). Leaving it here for reference for others. Also, maybe converting the value into a string internally would be good, as passing a number for the value will cmdk throw an error.

<Command.Root shouldFilter={false}>
    <Command.Input
        name="nameToSearch"
        placeholder="Search ..."
    />

    <Command.List>
            {#each result as data (data?.id)}
                <Command.Item
                    value={String(data?.id)}
                >