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

Dropdown items are not selectable on mobile devices when rendering to a portal element #1600

Open
aliceHendicott opened this issue May 6, 2024 · 1 comment

Comments

@aliceHendicott
Copy link
Contributor

  • downshift version: v9.0.4
  • node version: 20.12
  • npm (or yarn) version: yarn v1.22.19

What you did:

We have a use case where we are rendering the dropdown of our Select in a React portal. If we render the portal into document.body this works fine. However, we need to provide the option to render the portal to any user specified node id which may or may not exist. If it doesn't exist we create a div with the given id under document.body.

What happened:

When doing this, the dropdown options aren't selectable on mobile devices and a TriggerButtonBlur event is dispatched by Downshift.

Reproduction repository:

I've set up a recreation of this in CodeSandbox here.

To reproduce:

  • Open preview of app in new tab
  • Open dev tools and switch to responsive mode
  • Try to select an item
  • The dropdown will close without selecting the item
Screen.Recording.2024-05-06.at.11.55.45.AM.mov

Problem description:

Items are not selectable on mobile devices if the dropdown is not rendered until a certain condition is met (in this case until the Portal node has been created). The problem here lies in the useMouseAndTouchTracker hook where the downshiftElementRefs are excluded from the useEffect dependency array since "refs don't change".

Suggested solution:

The ideal solution here would be adding downshiftElementRefs to the dependency array but hoping to understand the original reason behind excluding this. Happy to raise a PR for this change.

If this exclusion is desired, are there any suggestions for how this use case could be resolved?

@joker-777
Copy link

This feature would be very helpful!

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