JedWatson / react-select

The Select Component for React.js
https://react-select.com/
MIT License
27.44k stars 4.1k forks source link

Scroll selected option into view when receiving refs #5784

Open JefHellemansBlockbax opened 8 months ago

JefHellemansBlockbax commented 8 months ago

Fixes:

And is a less hacky solution than: https://github.com/JedWatson/react-select/pull/4477

Please let me know if I can do anything to help get this merged and released.

changeset-bot[bot] commented 8 months ago

⚠️ No Changeset found

Latest commit: d9955afed052c220f192c614dbd4845aa042a213

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

codesandbox-ci[bot] commented 8 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d9955afed052c220f192c614dbd4845aa042a213:

Sandbox Source
react-codesandboxer-example Configuration
JefHellemansBlockbax commented 8 months ago

While looking at this again I noticed that another option is to make these refs part of the state. That way, when they get updated the componentDidUpdate function will trigger, causing the scrollIntoView call in there to be called. That is probably the best solution, and I'm willing to implement it in this PR if that helps. Feedback on both ideas (or either one really) would be much appreciated. We would love to get an updated version of react-select released in our product, as this functionality is currently broken for us. Based on the issues linked, it looks like we won't be the only ones benefitting from this change.

For now we'll implement a patch in our own code base, but that is something we would rather get rid of as soon as possible.