From cb76a24bd5869094f00aa8e4b02333720dce17a4 Mon Sep 17 00:00:00 2001 From: mister-ben Date: Thu, 25 Apr 2024 18:38:05 +0200 Subject: [PATCH] fix: Support MacOS trackpad with tap-to-click (#8700) --- src/js/utils/dom.js | 5 +++++ test/unit/utils/dom.test.js | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/js/utils/dom.js b/src/js/utils/dom.js index b6c2caea20..6b5f35cc34 100644 --- a/src/js/utils/dom.js +++ b/src/js/utils/dom.js @@ -773,6 +773,11 @@ export function isSingleLeftClick(event) { return true; } + // MacOS Sonoma trackpad when "tap to click enabled" + if (event.type === 'mousedown' && event.button === 0 && event.buttons === 0) { + return true; + } + if (event.button !== 0 || event.buttons !== 1) { // This is the reason we have those if else block above // if any special case we can catch and let it slide diff --git a/test/unit/utils/dom.test.js b/test/unit/utils/dom.test.js index 8a01d7068c..0a1c1bf0f2 100644 --- a/test/unit/utils/dom.test.js +++ b/test/unit/utils/dom.test.js @@ -656,12 +656,6 @@ QUnit.test('isSingleLeftClick() returns true for mouseup event', function(assert QUnit.test('isSingleLeftClick() checks return values for mousedown event', function(assert) { const mouseEvent = TestHelpers.createEvent('mousedown'); - // Left mouse click - mouseEvent.button = 0; - mouseEvent.buttons = 0; - - assert.notOk(Dom.isSingleLeftClick(mouseEvent), 'a left mouse click on an older browser (Safari) is a single left click'); - // Left mouse click mouseEvent.button = 0; mouseEvent.buttons = 1; @@ -685,6 +679,12 @@ QUnit.test('isSingleLeftClick() checks return values for mousedown event', funct mouseEvent.buttons = undefined; assert.ok(Dom.isSingleLeftClick(mouseEvent), 'a touch event on simulated mobiles is a single left click'); + + // MacOS trackpad "tap to click". Sonoma always does this, previous MacOS did this inconsistently, buttons was usally 1. + mouseEvent.button = 0; + mouseEvent.buttons = 0; + + assert.ok(Dom.isSingleLeftClick(mouseEvent), 'a tap-to-click on Mac trackpad is a single left click'); }); QUnit.test('Dom.copyStyleSheetsToWindow() copies all style sheets to a window', function(assert) {