JedWatson / JedWatson/react-select

Select not scrolling to Selected Item when menuPortalTarget={document.body}

Open
#5,926 1 comment 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When setting the MenuPortalTarget prop to document.body it breaks the functionality of correctly scrolling/focusing on the selected Item when it is at the bottom/out of view in the options list.
Example Code from the sandbox:
<Select className="basic-single" classNamePrefix="select" defaultValue={colourOptions[0]} isDisabled={isDisabled} isLoading={isLoading} isClearable={isClearable} isRtl={isRtl} isSearchable={isSearchable} name="color" options={colourOptions} menuPortalTarget={document.body} />

Image of Silver which is the last option not showing when it is selected and the select is opened again
Screenshot 2024-06-24 at 1 14 49 PM

Switching to menuPortalTarget={null} resolves the issue

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 by reproducing the sandbox example with menuPortalTarget set to document.body, then compare it with menuPortalTarget={null}. Trace the select menu's selected-item focus and scrolling behavior in the portal case; done means a selected option at the bottom or outside the visible list is scrolled into view when the menu reopens.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.