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

onFocus causes auto scroll to x=0 when search is hidden #1686

Closed
demesne opened this issue Dec 13, 2013 · 7 comments · Fixed by #2727
Closed

onFocus causes auto scroll to x=0 when search is hidden #1686

demesne opened this issue Dec 13, 2013 · 7 comments · Fixed by #2727

Comments

@demesne
Copy link

demesne commented Dec 13, 2013

When search box is hidden, and a chosen select is clicked(only on focus), the page auto-scrolls to the hidden search input box, which should not be the case.

Sample:-

http://jsfiddle.net/2bVBN/

@tjschuck
Copy link
Member

I can reproduce in Safari using the provided Fiddle.

Thanks for reporting, @demesne.

@demesne
Copy link
Author

demesne commented Jan 4, 2014

Did some css inspection, particularly around .chosen-container-single-nosearch .chosen-search and was wondering about the use-case for using position: absolute; left: -9999px; instead of not displaying it by using display: none;.
I'm asking this because I've seen the issue to be fixed by using the latter approach to not showing the search-box.

demesne added a commit to demesne/chosen that referenced this issue Jan 4, 2014
Changing the search box from being placed at -9999 to not being
displayed.
@pfiller
Copy link
Contributor

pfiller commented Jan 6, 2014

I've tried this in both Chrome and Safari and I'm not seeing the problem. Can you guys walk me through this step-by-step and tell me exactly what I'm looking for?

@tjschuck
Copy link
Member

tjschuck commented Jan 6, 2014

@pfiller In the Fiddle, scroll all the way to the right, and click the right-most Chosen select. The scroll position jumps all the way back to the left.

@pfiller
Copy link
Contributor

pfiller commented Jan 6, 2014

Thanks @tjschuck. Got it.

This is caused by two lines that are calling focus() on the hidden search field. I don't know or remember why it's called twice, but it doesn't really matter as once is enough to cause the jump in scrolling.

The most straightforward solution is to not call focus on the disabled search field. Unfortunately, that looks something like this right now as there's no method to tell if it should be disabled. We should add one!

@search_field.focus() unless @disable_search or @form_field.options.length <= @disable_search_threshold

@cnu2014
Copy link

cnu2014 commented Feb 18, 2014

Great work on the Plugin!. Just updated to v1.1.0. I see the this issue is not just limited to scrolling to x=0 when selecting using mouse. When the chosen drop down receives focus while tabbing the scrolling is still occurring. I have applied above fix with respect to search_field.focus() in chosen.jquery and has helped when selecting using mouse( scrolling doesn't happen) but this still scrolls when tabbing.
I am trying to figure out how do we get a handler to stop this auto scroll to x=0 while tabbing.
Any ideas are much appreciated.

@jjustaments
Copy link

Hi guys,

We also run in this issue.
As a workaround we 'focus' call put inside the IF statement.

if (!this.container.hasClass("chosen-container-single-nosearch")) {
  this.search_field.focus();
}

koenpunt added a commit that referenced this issue Oct 21, 2016
* clip results instead of moving them

fixes #1413
fixes #1410
fixes #1686
fixes #2402
fixes #2445
fixes #2185

* no more need for rtl fix in demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants