Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hitting enter adds a new item instead of selected item when searching (when addable is enabled) #594

Open
stv8 opened this issue Jan 13, 2025 · 5 comments

Comments

@stv8
Copy link

stv8 commented Jan 13, 2025

Describe the bug
I have addable enabled to allow creation, however if I do a partial search -> hit down arrow to select the item -> hit enter -> the partial search is created rather than the selected item added.

I would expect the item selected via the down arrow to be the one selected and not and item created.

Below is a code pen and a video reproducing the issue. Let me know if you need any more details, thanks!

Recreate it in Codepen
https://codepen.io/stv8/pen/MYgGeEB

To Reproduce
Steps to reproduce the behavior:

  1. ensure addable is on
  2. Click on input and type "1"
  3. select "option 1" by clicking down arrow
  4. hit enter
  5. observer that "1" is added in the box rather than the "Option 1"
  6. See error
CleanShot.2025-01-13.at.10.22.14.mp4
@stv8 stv8 changed the title Hitting enter adds a nea item instead of selected item when searching Hitting enter adds a new item instead of selected item when searching (when addable is enabled) Jan 13, 2025
@brianvoe
Copy link
Owner

That is a good catch. Basically what needs to happen is if they press down set a variable to indicate to not add and if they start typing. reset it to add again.

@stv8
Copy link
Author

stv8 commented Jan 13, 2025

word, are you suggesting to do that on my side as part of the search logic? or as a fix for the lib internally

@brianvoe
Copy link
Owner

That would need to be done in slim select. If you want to submit a pr I can get it in much quicker.

@stv8
Copy link
Author

stv8 commented Jan 13, 2025

Sounds good, I'll see if I can get to it in the next few days. From a quick glance it looks like this is the line where we would need to take into consideration whether the user has typed or not?

case 'Enter':
if (this.callbacks.addable) {
addable.click()
return false

@brianvoe
Copy link
Owner

yep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants