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

fix(onMouseMove): only call handler on non-touch devices #1571

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Feb 19, 2024

What:
Don't call the onMouseMove handler when a touch event is detected.

Why:
Not really needed, since on mobile we don't highlight items with touch.
It also causes a sequence of batched dispatch calls that are difficult to understand and, most probably, wrong.
On mobile, when touching to select an item, we had a couple of batched dispatch calls:

  1. item click
  2. item mouse move + item click.
    To me, it did not make sense. On non-mobile, it was fine, mouse move when mouse actually moved, and click after click. Nothing else.

Now we should only get itemClick on mobile when we touch to select an item.
Closes #1540.
Closes #1566.
Closes #1447.

It should also fix our example with Basic multiple selection. Once this PR will get merged, the example also needs to have the selectedItem passed as null, as the example already does not care about it since we keep the selectedItems as custom state. Passing selectedItem as null controlled prop will also make the onSelectedItemChange get called on successive item clicks.

How:
Check if we have onTouchDown, and if so, don't call dispatch in the onMouseMove handler. We update the useMouseAndTouchTracker to provide us with the value.
Also a few changes:

  1. Don't call ControlledPropUpdatedSelectedItem on first render, since we already get the proper selectedItem + input value combination in the initial state setup.
  2. Use a custom hook to get isInitialRender info.
  3. Check if state changed by also merging previous state with actual props, since that makes sense in the controlled component scenario.

Checklist:

  • Documentation
  • Tests
  • TypeScript Types
  • Flow Types
  • Ready to be merged

Copy link

🎉 This PR is included in version 8.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jeffijoe
Copy link

This also happens when using browser automation (Playwright in my case), and the fix for mobile doesn't apply there. Adding a delay to the click action in Playwright is a workaround but I don't want that to be a permanent solution.

Basically what seems to be happening is the item's onMouseMove is triggered in the same frame as the click (which doesn't normally happen on non-mobile devices).

I'm working on a simple reproduction repository including the Playwright setup and will open a new issue.

@jeffijoe
Copy link

I have reproduced this with Playwright and opened an issue #1597

@silviuaavram
Copy link
Collaborator Author

as long as this works for the end user, I would consider it closed. please reopen if you can repro as a normal user. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants