pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.04k stars 259 forks source link

`data-selected=true` is checked by value #199

Closed zilahir closed 5 months ago

zilahir commented 6 months ago

If the 2 Item has the same value, when one is selected (hovered) both items will receive the data-selected=true attribute, which makes both of them selected.

<>
<Item onSelect={(): void => select(1)}>
   Value 1
</Item
<Item onSelect={(): void => select(2)}>
   Value 1
</Item
</>

Hovering the first Item will also selet the second Item.

After a quick check the reason is possibly here:

https://github.com/prestonbourne/cmdk/blob/c7364e1e552788b842c840f68f9c159ad5810d04/cmdk/src/index.tsx#L583C3-L583C84

That the selected is set on value check.

Update:

It's actually stated in the docs:

Item that becomes active on pointer enter. You should provide a unique value for each item

However, I still think this should be changed.

pacocoursey commented 5 months ago

You should provide a unique value for each item.