Skip to content

[DropdownMenu][ContextMenu] Prevent text selection on menu close in Firefox #812

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

Merged
merged 1 commit into from
Aug 13, 2021

Conversation

jjenzz
Copy link
Contributor

@jjenzz jjenzz commented Aug 3, 2021

Hopefully the code comments explain clearly what is going on here 🤞

Fixes #742.


UPDATE: The original change I made here was no longer needed as the changes I made to fix Dialog.Trigger / DropdownMenu.Item composition also fixed this.

I've updated the code comments to explain that it covers this case too and the explanation as to why it fixes this is as follows:

Browsers wait for our handler logic to execute before executing their own implementation in case we have prevented their default behaviour. Therefore, the menu will unmount before the browser's pointerup logic has executed causing pointerdown to be stuck in some browsers. In FF this resulted in text selection occurring on the page when moving the mouse after close. We move the unmount logic till after the browser receives the pointerup to avoid this.

@jjenzz jjenzz force-pushed the firefox-menu-text-selection branch 3 times, most recently from a5c7d07 to f856ae1 Compare August 3, 2021 13:34
@andy-hook
Copy link
Contributor

I remember exploring a similar approach for fixing #634 but abandoned because we discussed doing something with event composition instead.

I've just tested that issue and it does indeed fix it as well 👍 this raises the question of whether we're ok introducing this timer, I'm personally fine with it for now given the absence of an alternative approach.

Do we see any unexpected issues resulting from the timer though?

@jjenzz jjenzz force-pushed the firefox-menu-text-selection branch from 4221db6 to 7fe64fc Compare August 3, 2021 15:37
@jjenzz jjenzz marked this pull request as draft August 3, 2021 16:58
@jjenzz jjenzz force-pushed the firefox-menu-text-selection branch from 7fe64fc to 9c29421 Compare August 12, 2021 15:39
@jjenzz jjenzz force-pushed the firefox-menu-text-selection branch from 9c29421 to f6ded60 Compare August 12, 2021 15:45
@jjenzz jjenzz marked this pull request as ready for review August 12, 2021 16:04
@jjenzz jjenzz merged commit f3e1620 into main Aug 13, 2021
@jjenzz jjenzz deleted the firefox-menu-text-selection branch August 13, 2021 10:22
@nvie
Copy link

nvie commented Aug 18, 2021

Amazing, thanks for the fix!

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

Successfully merging this pull request may close these issues.

[DropdownMenu] Using mouse to select drop down item traps mouse in active text selection
3 participants