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

Auto-update menu position when using menu portalling #5256

Merged
merged 16 commits into from Oct 12, 2022
Merged

Conversation

Methuselah96
Copy link
Collaborator

@Methuselah96 Methuselah96 commented Jul 4, 2022

Fixes #3533.
Fixes #4088.
Fixes #4159.
Fixes #4336.

This PR makes it so that when using menu portalling, event listeners are attached to the scrolling parents of the Select component in order to update the position after scroll or resize of one of its parents. This is accomplished using Floating UI's autoUpdate function and is heavily inspired by their useFloating hook (but doesn't directly use it in order to make this more minor of a change).

Previously I was trying to rewrite all of menu positioning, but I decided to go with this more modest approach to get this resolved more quickly and make it less of a breaking change. However a complete rewrite of menu positioning might still happen in the future if proven necessary.

I attempted to make this change as backwards compatible as possible. The only change should be that there are event listeners attached to the Select component's scroll parents if using menu portalling. It could be argued that this is either a bug fix, a new feature, or a breaking change. My leaning would be to release this in a minor version since I can't think of a use case where one would not want the menu position to update when the Control element moves.

@changeset-bot
Copy link

changeset-bot bot commented Jul 4, 2022

🦋 Changeset detected

Latest commit: 2c89e0e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-select Minor

Not sure what this means? Click here to learn what changesets are.

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 4, 2022

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 2c89e0e:

Sandbox Source
react-codesandboxer-example Configuration
react-select-v3-sandbox (forked) Issue #4088
react-select-v3-sandbox Issue #4088
recursing-nash-tt2tx6 Issue #4088
react-codesandboxer-example Issue #4088
react-codesandboxer-example Issue #4159
react-select-v3-sandbox (forked) Issue #4336

@Methuselah96 Methuselah96 changed the title Auto-update menu position when using portalling Auto-update menu position when using menu portalling Jul 4, 2022
@Methuselah96
Copy link
Collaborator Author

@ryan-castner Thanks for trying out the branch. I am not able to reproduce the issue you're experiencing. I've pushed a test of menuPlacement="auto" to https://github.com/JedWatson/react-select/tree/use-floating-with-test and get this result:

image

You can try it out by checking out that branch, starting the docs with yarn start, and navigating to localhost:8000/cypress-tests. Let me know if you can provide any more info regarding the issue you're experiencing.

Copy link
Collaborator

@lukebennett88 lukebennett88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @Methuselah96!
I couldn't replicate the issue that @ryan-castner mentioned.
I agree that a minor makes sense here 👍

@Methuselah96 Methuselah96 enabled auto-merge (squash) October 12, 2022 23:08
@Methuselah96 Methuselah96 merged commit 598f9ee into master Oct 12, 2022
@Methuselah96 Methuselah96 deleted the use-floating branch October 12, 2022 23:14
@github-actions github-actions bot mentioned this pull request Oct 12, 2022
@Methuselah96
Copy link
Collaborator Author

This has been released in react-select@5.5.0. We anticipate this change to be non-breaking which is why we're releasing it in a minor release, but if it turns out that this change is (non-trivially) breaking, it's possible we might revert the change and re-release it in a major version.

@csandman
Copy link

This is awesome, thank you so much for this change! I've been experiencing this issue in my wrapper chakra-react-select for a while and I'm so glad to see it get fixed!

@alk-sdavid
Copy link

alk-sdavid commented Oct 14, 2022

Hi @Methuselah96, thank you for this change, but I can confirm it's a major release which introduces some breaking change since it relies on @floating-ui/dom which relies itself on ResizeObserver. It breaks old browsers which does not support ResizeObserver. So I guess you should release it as version 6.0.0, and indicate this requirement in the changelog and the documentation.

Thanks again for your work and I hope it helps.

@Methuselah96
Copy link
Collaborator Author

@alk-sdavid Which browsers are you trying to support? As far as I know we don't have any browser support policy at the moment besides not IE 11 (mentioned in the v5 upgrade guide).

Methuselah96 added a commit that referenced this pull request Oct 14, 2022
Resolves #5256 (comment).

We do not have an official browser support policy, but it would be nice to delay relying on `ResizeObserver` for a major bump and make our official browser support policy clear.

I do not believe we anticipate the `ResizeObserver` getting triggered in many situations anyway since the menu itself shouldn't be resizing. The scroll events are much more critical to auto-updating working properly.
@Methuselah96
Copy link
Collaborator Author

Methuselah96 commented Oct 14, 2022

Looks like Safari on iOS 12.5 and Android Browser 4.4.4 might be the two browsers that don't support it if we're aiming to support browsers with >.25% usage.

I've created #5381 to disable the ResizeObserver for now, and we can (potentially) re-enable it and make our browser support policy clear in the next major version.

@alk-sdavid
Copy link

Hi, yes it was not IE11, I just tested react-select on browserstack with some browser which does not support ResizeObserver (https://caniuse.com/resizeobserver). I do not have any issue about it, but I was just thinking it would be better to make a major release and to make it clear in the changelog and the documentation.
FYI, I noticed the ResizeObserver because some of my company unit tests failed because of it on a Dependabot pull-request, and then I dug a bit…

@kimi-truong
Copy link

Hi @Methuselah96, I've just upgraded to the latest version v5.5.0 and all unit tests failed because of ResizeObserver

ReferenceError: ResizeObserver is not defined

Do you have any workaround on it?

@Methuselah96
Copy link
Collaborator Author

It should be resolved by #5381 which will hopefully be released in the next couple days.

Methuselah96 added a commit that referenced this pull request Oct 16, 2022
* Disable use of ResizeObserver for menu auto-update

Resolves #5256 (comment).

We do not have an official browser support policy, but it would be nice to delay relying on `ResizeObserver` for a major bump and make our official browser support policy clear.

I do not believe we anticipate the `ResizeObserver` getting triggered in many situations anyway since the menu itself shouldn't be resizing. The scroll events are much more critical to auto-updating working properly.

* Create new-sloths-wink.md
@Methuselah96
Copy link
Collaborator Author

@alk-sdavid @kimi-truong This should be resolved in react-select@5.5.1, let me know if you have any more issues.

@kimi-truong
Copy link

@Methuselah96 thanks so much 🙏 , it works now.

Rall3n pushed a commit to Rall3n/react-select that referenced this pull request Oct 19, 2022
* yarn install

* Add floating-ui

* Make MenuPortal function component

* Fix csstype resolution

* Update

* Remove unnecessary export

* Avoid ResizeObserver

* Create soft-bags-shave.md

* Include fixed

* Update

* Update

* Fix

* Bump @floating-ui/dom

* Format
Rall3n pushed a commit to Rall3n/react-select that referenced this pull request Oct 19, 2022
* Disable use of ResizeObserver for menu auto-update

Resolves JedWatson#5256 (comment).

We do not have an official browser support policy, but it would be nice to delay relying on `ResizeObserver` for a major bump and make our official browser support policy clear.

I do not believe we anticipate the `ResizeObserver` getting triggered in many situations anyway since the menu itself shouldn't be resizing. The scroll events are much more critical to auto-updating working properly.

* Create new-sloths-wink.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants