JedWatson / JedWatson/react-select
React-Select scrolls window instead of scrollable parent div
Nobody has claimed this yet.
- 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:
- When a
<Select>menu is opened, if the menu is not completely in view, React-Select uses itsscrollTofunction to try to scroll the menu onto the screen. - The
getScrollParentfunction is used to obtain the menu's scroll parent. - Because no
positionrule was set on any element above the menu, thestyle.position === 'static'condition returned true for every parent. SogetScrollParentreturneddocument.documentElement. - This caused
scrollToto callwindow.scrollTo.
Maybe this can be fixed by using Element.scrollIntoView?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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