JedWatson / JedWatson/react-select

React-Select scrolls window instead of scrollable parent div

Open
#4,539 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-confirmed menu-bug
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Our app has a tab-like page layout, where we set overflow: "hidden" on the page in favor of having a scrollable div containing the tab's contents. For additional context, this marketing page contains a video that shows this layout.

Bug: when the menu is opened, the <Select> calls window.scrollTo instead of scrolling the tab content div. If there's an element on the page positioned offscreen (e.g. a Bootstrap .sr-only element), Google Chrome (but not Firefox) actually scrolls the page. This is an issue because the overflow: "hidden" rule then prevents users from scrolling back up to the rest of the app.

Minimal repro sandbox: https://codesandbox.io/s/repro-reactselect-windowscrollto-jqghv?file=/src/Example.js

Additional details

We've tracked down the cause to getScrollParent:

  1. When a <Select> menu is opened, if the menu is not completely in view, React-Select uses its scrollTo function to try to scroll the menu onto the screen.
  2. The getScrollParent function is used to obtain the menu's scroll parent.
  3. Because no position rule was set on any element above the menu, the style.position === 'static' condition returned true for every parent. So getScrollParent returned document.documentElement.
  4. This caused scrollTo to call window.scrollTo.

Maybe this can be fixed by using Element.scrollIntoView?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/react-select/src/utils.js, especially getScrollParent and scrollTo, and reproduce the behavior in the linked CodeSandbox. Trace how a menu inside an overflow-hidden page identifies its scrollable parent; done means opening an offscreen menu scrolls the containing div without moving the window, with the existing Firefox behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.