closing dropdown which is out of the viewport causes viewport to scroll
#3,663 建立於 2015年8月7日
描述
Version: Select2 4.0
Example: https://jsfiddle.net/z7L1px15/
To reproduce:
- In the above fiddle click the select2 dropdown to open it.
- Scroll the viewport down to the 2nd input and click it to focus on it
What is expected: The 2nd input will have the focus and be visible.
What happens: The 2nd input receives the focus, but the viewport scrolls up to the select2 dropdown so the focused input is no longer visible.
This seems like somewhat of an edge case but we see people hit it with some regularity on a longish form where the submit button is at the bottom of the page. Users will decide not to change a select2 enabled field after opening, and scroll down and click the submit button to save other changes, then get confused when the page jumps back up. They have to scroll back down to the bottom and click the submit button again for the form to be submitted.
The line responsible is https://github.com/select2/select2/blob/master/src/js/select2/selection/base.js#L84 That line returns the focus to the element after the dropdown closes. I think what we really want is for this focus event to occur only when a value is selected, not every time the dropdown is closed.