Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
goldpvlv opened this issue Dec 13, 2023 · 2 comments

Comments

@goldpvlv
Copy link

goldpvlv commented Dec 13, 2023

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

@yoyo837
Copy link
Member

yoyo837 commented Dec 13, 2023

The answer is the same as ant-design/ant-design#46401 (comment)

In addition, this repo is also maintained by antd members. :)

@goldpvlv
Copy link
Author

goldpvlv commented Dec 13, 2023

The answer is the same as ant-design/ant-design#46401 (comment)

In addition, this repo is also maintained by antd members. :)

@yoyo837 It's great that you can also advise on antd here!
I understand that there is no answer to my comment, because AutoComplete was conceived exactly as it is now. But I need the label to be in the input field, not the value. I was offered to change the component to Select with the showSearch parameter. But his behavior doesn't suit me either. For my task, I am satisfied with AutoComplete, but I cannot cope with scrolling so that the selected element is displayed when opening. Maybe you can recommend something?
Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants