Skip to content

Context menu trigger should call provided onContextMenu even when not disabled #646

@joakimbeng

Description

@joakimbeng

Is your feature request related to a problem? Please describe.

Currently any provided onContextMenu handler to the ContextMenuTrigger component is only called when the trigger is disabled (see context-menu-trigger.tsx Line 90-92).
Why is this so? I want access to the coordinates for where the context menu was triggered and still want the built-in functionality that the trigger provides (like long press on touch devices). To get access to the coordinates I have to opt-out of that functionality and implement it myself.
Only calling the provided event handler when disabled seems inconsistent with how other components behave.

As I only need the coordinates I was hoping the context had those, but I'm afraid it doesn't. The context only contains the setter for the anchor rect and not the getter, so I can't use that either.

Describe the solution you'd like

Either add the anchor rect getter to the context menu context or move the callhandler call for onContextMenu so it's called no matter if the trigger is disabled or not.
Maybe even both solutions would be preferable. And even better if the built-in onContextMenu handler took defaultPrevented into account so that it's possible to use event.preventDefault() in your own onContextMenu handler to opt-out of the default behaviour.

Describe alternatives you've considered

Covered in the solution suggested

Additional context
.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions