[Bug]: Issue with autofocus on the first option when using search
Bug description
On a multiple select with a long list of option, you can start typing to filter the results to show. When filtered, the focus is automatically applied to the first option of the list. If you click on an option to select it, the focus is automatically re applied to the first option. This is an issue on list with many options because the dropdown scroll up to the first option every time we select an option.
This issue only happens when we use the search to filter the options. When we do not use it, there is no automatic focus on the first option.
Expected behavior
The first option should not be focused after we select an option. Or we should be able to disable the auto focus on search.
Steps to reproduce
- Add a
selectwith themultipleproperty and many options - Click on select and start typing
- Scroll down the list of option and select any of them
- See that the dropdown automatically scroll up to the first item
Additional context
- Tom Select 2.4.1
The issue can be observed in the Examples on tom-select.js.org
https://github.com/user-attachments/assets/9a193ad0-98f0-4736-b07d-6fd05e8bc573
looks like is caused by this line https://github.com/orchidjs/tom-select/blob/2efbaab0abac19532bd38900f13b99762df601b4/src/tom-select.ts#L894
which leads to active_option to not be assigned in refreshOptions,
and then effectively assigned to be the first option in the list (and scrolled to afterwards)
related https://github.com/orchidjs/tom-select/issues/556