JedWatson / JedWatson/react-select

autoFocus=TRUE incorrectly scrolls the page when it is higher than the viewport

Open
#3,322 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When a page does not fit into a viewport, i.e. there is a scrollbar in the browser tab, using autoFocus on AsyncSelect causes the page to scroll incorrectly. In my case, it scrolls all the way down, which results in the AsyncSelect being hidden from the viewport.

The workaround that worked for me is setting autoFocus={false} and using componentDidMount in the wrapper component:

setTimeout(() => {
            if (this.selectRef.current) {
              this.selectRef.current.focus();
          }
        }, 400);

Here, selectRef is initialized in the following way:

<AsyncSelect
            ref={this.selectRef}
/>

To make it more specific, I have a Twitter Bootstrap 4 based HTML page, with a navbar. The navbar is non-fixed and non-floating, i.e. it scrolls when you scroll the page.

Inside the navbar, floated to the right is a <button>, and a <Popper> element is next to it (React-UI). When the button is clicked, the Popper is shown.

The AsyncSearch is inside a Popper.

Navbar

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 at AsyncSelect's autoFocus behavior and reproduce the issue in a page taller than the viewport, with the select inside a Popper. Compare focusing during mounting with the delayed ref focus described in the workaround. Done means enabling autoFocus no longer scrolls the page far enough to hide the AsyncSelect.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.