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

Should onPointerDown event on DropdownMenuTrigger replaced with onClick handler? #3012

Closed
mellosti opened this issue Jul 11, 2024 · 2 comments

Comments

@mellosti
Copy link

I am trying to use the DropdownMenu on a component that can be dragged. However, the onPointerDown handler (see here) on the DropdownMenuTrigger prevents the trigger from being dragged. I replaced it with onClick and solved the issue locally. I can now both drag the trigger and also click to open the dropdown.

Why is onPointerDown used instead of onClick? Can we replace it?

My code:

    <DropdownMenu>
      <DropdownMenuTrigger asChild>
       <button draggable={true} onDrag={onDrag} ...>Drag me!</button>
      </DropdownMenuTrigger>
      <DropdownMenuContent>
          ...
      </DropdownMenuContent>
    </DropdownMenu>
@duhaime
Copy link

duhaime commented Feb 24, 2025

@chaance @hadihallak is this library still maintained?

@chaance
Copy link
Member

chaance commented Feb 24, 2025

Yes, it's still maintained. This behavior is by design. Opening the menu on pointerdown more closely mirrors behavior of dropdown menus on native platforms.

I'm not sure we can handle this case internally without creating a delay on the open state to try and determine the user's intent to drag, which isn't a great UX for the vast majority of users. This would also pose some accessibility challenges.

You should be able to work around this by controlling the state yourself and only calling the change handler when the user has completed a click. Might add a bit of complexity to your code, but I'm not convinced this should be baked into the component's behavior.

@chaance chaance closed this as completed Feb 24, 2025
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

3 participants