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

fix: Support MacOS trackpad with tap-to-click #8700

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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