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

bug?: defining left click as trigger type triggers "oncontextmenu" of trigger button #754

Open
arashdalir opened this issue Sep 22, 2021 · 1 comment

Comments

@arashdalir
Copy link
Contributor

I have encountered an unexpected side-effect of the left-click handling in the code: we have a trigger button inside a slick-grid table structure, our slick-grid cells have a handler for onContextMenu and we are now facing a major issue with the trigger button! it's calling the slick-grid handler instead of calling the contextMenu creator.

following GIF shows the issue. the yellow clicks are left-click, the red ones are right-click...

contextMenu-leftClick

reason for it is the code below. clicking the trigger button is calling the contextMenu event, which in return triggers the onContextMenu function defined later on in our slick-grid section.

any suggestions how to avoid this?

  • one solution is to detect that the onContextMenu was triggered artificially in the slick-grid code and not to continue that function. this would require that the code knows that the trigger (event target) is a contextMenu object. I have not been able to find any plugin command or helper which would facilitate this.
  • another and well, a better solution is to rewrite the code below to avoid calling contextMenu event! technically, it should be possible to define 2 different sets of actions for left-clicking or right-clicking an element and this piece of code is forbidding it...
//jquery.contextMenu.js:351 - v2.9.2
// contextMenu left-click trigger
click: function (e) {
  e.preventDefault();
  e.stopImmediatePropagation();
  $(this).trigger($.Event('contextmenu', {data: e.data, pageX: e.pageX, pageY: e.pageY}));
},
@arashdalir
Copy link
Contributor Author

arashdalir commented Sep 22, 2021

PS: I used $.contextMenu.menus to check if the event target is one of the contextMenu selectors, partially implementing my first solution, but now there is another issue. I cannot determine in my slick-grid code if I have right-clicked or left-clicked on the button (code posted below).

gGrid.on(
	"ContextMenu",
	function (e, args){
		var $t = $(e.target);

		var isContextMenu = false;

		$.each($.contextMenu.menus, function(ns, o){
			if ($t.is(o.selector))
			{
				isContextMenu = true;
			}
		});

		if (isContextMenu)
		{
			return;
		}
...

as I have seen in the code, there are 4 code parts which actually trigger the contextmenu: handlers for click, mouseup, mouseenter and on line 1621 which I honestly don't understand.

I suppose if the "original" event was passed as an argument of the new event, it would have been possible to determine in my slick-grid side of the code what the real called event used as trigger (left, mouseenter, mouseup etc.). something like $.Event('contextmenu', {data: e.data, pageX: e.pageX, pageY: e.pageY, originalEvent: e})

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

1 participant