radix-ui / primitives

Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
https://radix-ui.com/primitives
MIT License
15.93k stars 833 forks source link

[DropdownMenu] Fix touch devices trigger bug #3241

Open jasongerbes opened 4 days ago

jasongerbes commented 4 days ago

Description

Fixes an issue where DropdownMenuTrigger would open inadvertently on touch-based scroll (#1912).

The previous PR for this fix (#2616) was rejected as it broke a feature where the user can select an item in one click (pointer down on trigger, move, pointer up on item). This PR retains that behaviour.

See the related PR (#2939) for the Select component.

Touch before:

https://github.com/user-attachments/assets/3aab7419-c7be-4283-ba99-b849a89e1e61

Touch after:

https://github.com/user-attachments/assets/22590f10-e888-432e-aa2a-3d5eac08f02e

Pointer down behaviour for mouse devices has been preserved:

https://github.com/user-attachments/assets/506efe81-2d03-4676-90c1-350e707ac461

Note: I was unable to replicate #1658 (also addressed in #2939) with the Dropdown Menu component, so I haven't copied the changes that were made to SelectItem over to DropdownMenuItem. Happy to do so if you'd like me to.