[Bug]: contextmenu in V4 is not default-preventable
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.4k
- Forks
- 893
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 26
Description
Current versus expected behaviour
In v3.4, we had a context menu handler on an element:
this._paper.on('element:contextmenu', function(cellView, evt, x, y) {
evt.stopPropagation();
evt.preventDefault();
var str = '<LI>'+(cellView.model.get('showKeys' ) != true ? 'Show Keys' : 'Hide Keys')+'</LI>'
+'<LI>'+(cellView.model.get('showColumns') != true ? 'Show Columns' : 'Hide Columns')+'</LI>'
+'<LI>Remove from Canvas</LI>'
;
showContextMenu(str, evt.pageX, evt.pageY);
});
When inspecting the event, it was the proper "contextmenu" event, and so prevending default and stopping propagation would work in preventing the default context menu from the browser.
In V4 (we are upgrading!!!) this behavior no longer works. The issue i believe is that the event is not the "mousedown" event which triggers the contextmenu logic in joinjs. However, the default browser contextmenu responds to the "mouseup" event. As such, the stopPropagation and preventDefault calls have no effect because we are on the "wrong" event?
I couldn't not find documentation about this change of behavior and wonder if this is an error due to the removal of jQuery which was handling such things?
Steps to reproduce
Adding a contextmenu on an element cannot prevent default browser behavior
Version
4.0.2
What browsers are you seeing the problem on?
Firefox, Chrome, Microsoft Edge
What operating system are you seeing the problem on?
Windows
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the v4 contextmenu event handling and reproduce the issue with an element context menu in Firefox, Chrome, and Edge. Compare the dispatched event with the browser's default context-menu behavior; done means calling preventDefault and stopPropagation from the element handler consistently suppresses the browser menu.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100