question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-select does not scroll into view selected option

See original GitHub issue

I expect that the following will result in the selected option being shown as soon as the dropdown is opened. It does not. It highlights the selected option but you have to scroll to it in order to see it.

<Select
   options={[...Array(121).keys()].map(num => {return {value: num, label: num}})}
   value={{label: 20, value: 20}}
   isOptionSelected={(option) => (option.value == 20) ? true : false}
 />

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
akinorimizcommented, Nov 8, 2019

You can use a custom component.

const Option = (props) => {
    const ref = useRef();

    useEffect(() => {
        props.isSelected && ref.current.scrollIntoView();
    }, [props.isSelected]);

    return (
        <components.Option {...props} innerRef={ref} />
    );
};
4reactions
russyDevcommented, Jul 9, 2022

Issue still exist

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-select scrollintoView does not scroll the selected value
So I was able to solve this using onMenuOpen() call back function with timeOut as we do not have "MyDropdown__option--is-selected" class at the ......
Read more >
React-select scrollintoView does not scroll the selected value ...
Coding example for the question React-select scrollintoView does not scroll the selected value-Reactjs.
Read more >
API - React Select
This is useful when you have a scrollable modal and want to portal the menu out, but want to avoid graphical issues.
Read more >
Material Select not scrolling to selected value in long drop
Expected behavior When there are a large number of options in the dropdown and the items are in a scrollable list, it doesn't...
Read more >
Element.scrollIntoView() - Web APIs | MDN
Corresponds to scrollIntoViewOptions: {block: "start", inline: "nearest"} . This is the default value. If false , the bottom of the element will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found