From 35d1ab675753f1f88d0ead9dd8fce8c69d136057 Mon Sep 17 00:00:00 2001 From: Maira Bello Date: Mon, 29 Aug 2016 13:51:34 -0300 Subject: [PATCH] Stops triggering "click" events for right clicks on Firefox - Fixes #152 --- packages/metal-dom/src/dom.js | 7 +++++++ packages/metal-dom/test/dom.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/metal-dom/src/dom.js b/packages/metal-dom/src/dom.js index 73e084fc..855e4a93 100644 --- a/packages/metal-dom/src/dom.js +++ b/packages/metal-dom/src/dom.js @@ -730,6 +730,13 @@ class dom { * @protected */ static triggerMatchedListeners_(container, element, event, defaultFns) { + if (event.type === 'click' && event.button === 2) { + // Firefox triggers "click" events on the document for right clicks. This + // causes our delegate logic to trigger it for regular elements too, which + // shouldn't happen. Ignoring them here. + return; + } + var data = domData.get(element); var listeners = data.listeners[event.type]; var ret = dom.triggerListeners_(listeners, event, element, defaultFns); diff --git a/packages/metal-dom/test/dom.js b/packages/metal-dom/test/dom.js index 7c86557d..672a0ede 100644 --- a/packages/metal-dom/test/dom.js +++ b/packages/metal-dom/test/dom.js @@ -759,6 +759,20 @@ describe('dom', function() { assert.strictEqual(0, listener2.callCount); }); + it('should not trigger delegate "click" listener for right clicks', function() { + var element = document.createElement('div'); + dom.enterDocument(element); + var child = document.createElement('div'); + dom.append(element, child); + + var listener = sinon.stub(); + dom.delegate(element, 'click', child, listener); + dom.triggerEvent(child, 'click', { + button: 2 + }); + assert.strictEqual(0, listener.callCount); + }); + it('should run default listeners last', function() { var element = document.createElement('div'); dom.enterDocument(element);