react-component / react-component/select

Using scrollTo method of the dropdown list (menu) in the OptionList component

Open
#1,003 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
938
Forks
482
Avg merge
15h 8m
Merged PRs (30d)
2

Description

Hi, I have the following problem with OptionList. I am using the AutoComplete component in the antd library.
The dropdown list uses the optionList from rc-select. I need to scroll to the selected item in the input field when opening the dropdown list.
To do this, I use the useEffect hook when rendering the menu (RenderDropdownMenu), where I access the menu and call scrollTo to the desired index. But the hook is triggered every time the menu is rendered and returns to the selected item.
What can be done about it?
Reproduction:
https://codesandbox.io/p/sandbox/selectscrollto-29x7sc?file=%2Fdemo.tsx%3A130%2C20

  1. Select "value" in the dropdown
  2. Try scroll down or up

antd developers couldn't help
thanks

Contributor guide

No contributing guide indexed for this repository

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 the linked CodeSandbox reproduction and trace how OptionList is rendered through RenderDropdownMenu. Observe the scroll position after selecting an option and reopening or scrolling the dropdown. Done means the reported unwanted return to the selected item is addressed without losing the intended initial scroll behavior.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.