react-component / select

React Select
https://select.react-component.now.sh/
MIT License
892 stars 451 forks source link

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

Open goldpvlv opened 6 months ago

goldpvlv commented 6 months ago

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 commented 6 months ago

The answer is the same as https://github.com/ant-design/ant-design/issues/46401#issuecomment-1851433826

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

goldpvlv commented 6 months ago

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