Skip to content

Commit

Permalink
Stops triggering "click" events for right clicks on Firefox - Fixes #152
Browse files Browse the repository at this point in the history
  • Loading branch information
mairatma committed Aug 29, 2016
1 parent aa49bc6 commit 35d1ab6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/metal-dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions packages/metal-dom/test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 35d1ab6

Please sign in to comment.