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

closing dropdown which is out of the viewport causes viewport to scroll #3663

Open
rhec opened this issue Aug 7, 2015 · 10 comments
Open

closing dropdown which is out of the viewport causes viewport to scroll #3663

rhec opened this issue Aug 7, 2015 · 10 comments

Comments

@rhec
Copy link

rhec commented Aug 7, 2015

Version: Select2 4.0

Example: https://jsfiddle.net/z7L1px15/

To reproduce:

  1. In the above fiddle click the select2 dropdown to open it.
  2. 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.

@kevin-brown
Copy link
Member

Yup, was able to confirm this with the jsfiddle.

@stianlik
Copy link

stianlik commented Nov 29, 2016

This can also be observed in the following case:

  1. Click select2 dropdown to open it
  2. Scroll so that the dropdown is out of view
  3. Click somewhere outside the dropdown
  4. Observe that the viewport is scrolled back to the dropdown

@bantikyan
Copy link

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.
Does anybody have solution / workaround for this bug?

@alexweissman
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Apr 12, 2018

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.

@LOK-Soft
Copy link

I just submitted an pull-request, my change will not trigger focus() on element if there was an outside click

@pedrofurtado
Copy link
Contributor

The continuation of this discussion will be inside PR -> #5353

LOK-Soft pushed a commit to LOK-Soft/select2 that referenced this issue Oct 9, 2018
This reverts commit caeb650.
LOK-Soft pushed a commit to LOK-Soft/select2 that referenced this issue Oct 9, 2018
@kevin-brown kevin-brown reopened this Jul 28, 2019
@stale
Copy link

stale bot commented Sep 26, 2019

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.

@stale
Copy link

stale bot commented Dec 1, 2019

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.

@stale stale bot added the status: stale label Dec 1, 2019
@stale stale bot closed this as completed Dec 8, 2019
@Victor-Prodanov
Copy link

Please reopen issue #3663.

@paxnovem paxnovem reopened this Dec 16, 2019
@stale stale bot removed the status: stale label Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants