brianvoe / slim-select

Slim advanced select dropdown
http://slimselectjs.com
MIT License
1.07k stars 200 forks source link

Unable to select previously selected option after using deselect #576

Closed Gotenks-J closed 2 days ago

Gotenks-J commented 1 month ago

Describe the bug

After deselecting an option, then selecting the same option when using the search event does not select it

Potentially related to: https://github.com/brianvoe/slim-select/pull/555

Recreate it in Codepen

https://codepen.io/GotenksJ/pen/gOVWbzr

I was lazy with the Codepen and instead of using an API that returns the same data on each call I just set the options on search.

To Reproduce

Steps to reproduce the behavior:

  1. Click on the search input and search anything to bring up the results
  2. Select one of the returned options
  3. Click the deselect 'X'
  4. Click on the search input again and search to bring up the results
  5. Select the same option from step 2
  6. The option is not selected

https://github.com/user-attachments/assets/1b37cac3-adf0-4146-885a-f8c922e12a91

You can also see this issue in the documentation of the search event:

https://github.com/user-attachments/assets/a7b3a1e7-2b8a-49ed-9c9d-56948477cf66

brianvoe commented 1 month ago

Oooo thats a good catch!

Ill have to look into that. im guessing it has something to do with search that does data replacement based upon search results.

I have a few other things I need to finish up but if i get some time ill try to see if i can fix this.

If you think you can fix it. Git clone, npm install, npm run dev.

Gotenks-J commented 1 month ago

I think a better solution here is to set the id for options returned by the search event, this fixes the issue for me, e.g https://codepen.io/GotenksJ/pen/YzmregP

Maybe it's just a matter of updating the documentation to describe this, I think it's reasonable that the user is expected to set the id attribute when using search otherwise they're at the mercy of the ID generator.

Working example after updating the docs to set the id attribute:

https://github.com/user-attachments/assets/149d6788-38d8-4070-98da-7137840c199b

If you're happy with this I can look at updating the documentation to include this?

brianvoe commented 1 month ago

I can definitly see where your coming from but an id should be set no matter what even if it came from search cause i dump that into data right after.

i have some time tonight let me see if i can stare at that part for a sec

Gotenks-J commented 2 days ago

Closing this in favour of a better solution or we will resolve this by setting the ID attribute