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
closing dropdown which is out of the viewport causes viewport to scroll #3663
Comments
Yup, was able to confirm this with the jsfiddle. |
This can also be observed in the following case:
|
If I remove line you mentioned that causing this bug, focus will not be set and window will not be scrolled up, but if have submit button instead of 2nd input, submit event will not work. |
There is some discussion in #4983 (comment). @roman4e @zoka123 @jpic I have closed #4983 as a duplicate, so we will keep this open as the canonical issue. |
Any update on this? Having the same issue with a long page that has multiple select2 boxes. Not desirable to have the page scroll to the previous select2 if no selection is made and a click event occurs elsewhere. |
I just submitted an pull-request, my change will not trigger focus() on element if there was an outside click |
The continuation of this discussion will be inside PR -> #5353 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Please reopen issue #3663. |
Version: Select2 4.0
Example: https://jsfiddle.net/z7L1px15/
To reproduce:
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.
The text was updated successfully, but these errors were encountered: