Skip to content

Commit

Permalink
fix: Support MacOS trackpad with tap-to-click (#8700)
Browse files Browse the repository at this point in the history
  • Loading branch information
mister-ben committed Apr 25, 2024
1 parent 466fa97 commit cb76a24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/unit/utils/dom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit cb76a24

Please sign in to comment.