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

Add conditional scrolling into view of focused option #2170

Merged
merged 1 commit into from
Nov 26, 2017

Conversation

mtlewis
Copy link
Contributor

@mtlewis mtlewis commented Nov 25, 2017

Previously the focused option would be scrolled to the top of the scroll window when the menu is opened, regardless of whether it was already in view. An example of a situation where this is problematic is when a list starts with one or more disabled items. In this situation, the disabled items are scrolled out of view when the menu opens, and because they're at the top of the list it's hard to notice they're there.

This PR modifies the behavior such that when the menu is opened, it will only scroll the focused option into view if it's not already fully in view.

The current behavior is reproducible in the live demo:

  1. Open the live demo at http://jedwatson.github.io/react-select/
  2. Change the states demo to the US dataset
  3. Without typing, open the menu by clicking the input.
  4. Notice that it's hard to tell that there's a disabled option at the top of the list, especially in environments where the scrollbar is not always visible.

Previously the focused option would be scrolled to
the top of the scroll window when the menu is opened,
regardless of whether it was already in view.  An
example of a situation where this is problematic is
when a list starts with one or more disabled items.
In this situation, the disabled items are scrolled
out of view when the menu opens, and because they're
at the top of the list it's hard to notice they're
there.

This commit modifies the behavior such that when the
menu is opened, it will only scroll the focused option
into view if it's not already fully in view.
@mtlewis
Copy link
Contributor Author

mtlewis commented Nov 25, 2017

If this behavior is not something we can impose on everyone, I'd be happy to look at adding a prop controlling whether we do this check or not.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.363% when pulling 6eb31be on mtlewis:only-scroll-when-necessary into 1af9bec on JedWatson:master.

@JedWatson
Copy link
Owner

This looks like a good change, I'm happy to make it across the board 👍

Thanks for the PR and especially the clear instructions to reproduce! Made this really easy to test and merge.

@JedWatson JedWatson merged commit 1e8b26b into JedWatson:master Nov 26, 2017
@mtlewis
Copy link
Contributor Author

mtlewis commented Nov 26, 2017

No worries! Thanks @JedWatson for the quick turnaround, will look out for other ways to contribute more in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants