Close drop down when selecting item with enter key
This ensures that the drop down closes after choosing an item by pressing the enter key.
Fixes #2697
Hello,
Thank you for proposing a PR to fix an issue.
I cannot reproduce the bug in question: in my hands, pressing enter closes the dropdown. Tried with chromium and firefox on tests/bootstrap5.html. Is the bug reproducible?
I'll see if I can figure out the trick to reproducing. I saw two people mentioning it in discussions and we found it when we updating our django app to Bootstrap 5 with this package.
I don't mind merging it as it's a rather small change, but I also know that the smaller the change, the higher risk it has to break other stuff, so that's why I would prefer if it fixes a reproducible issue.
If I may suggest 3 things :
- I would close the dropdown on Enter or Tab if selectOnTab option is activated
- I would not call e.preventDefault() to let the focus jump to the next control when you validate your selection
- It might also seem more readable to insert your code on line 3170, just under this.trigger('focus'), which is called right after the item is actually selected.
Sorry if this is not the right way to comment on somebody else's pull request.
Hi, I don't want to unessacarily bump this but I can confirm that this issue is still present in alpha3 (we're currently in the upgrade process to bootstrap 5 as well). I wasn't able to track down any issues on our end why the dropdown menu isn't closing, but maybe I oversaw something...
@derklaro And does this change fixes the issue you see?
It does! :)
Looks like this pull request updated the "js/bootstrap-select.js" file but not the "js/bootstrap-select.min.js" file. Just FYI for anyone that might be trying to use this fix, the min and map files were not updated with the changes included in the "js/bootstrap-select.js file.