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

Include event.detail in click and dblclick events #1156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions addon-test-support/@ember/test-helpers/dom/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function __click__(
element: Element | Document | Window,
options: MouseEventInit
): void {
options = { ...options, detail: 1 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://github.com/emberjs/ember-test-helpers/blob/master/API.md#click

I believe this would be a breaking change as users could no longer override detail on the event.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, you'd have to do it the other way around (so the users provided detail option "wins"):

Suggested change
options = { ...options, detail: 1 };
options = { detail: 1, ...options};

let mouseDownEvent = fireEvent(element, 'mousedown', options);

if (!isWindow(element) && !mouseDownEvent?.defaultPrevented) {
Expand Down
3 changes: 3 additions & 0 deletions addon-test-support/@ember/test-helpers/dom/double-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function __doubleClick__(
element: Element | Document | Window,
options: MouseEventInit
): void {
options = { ...options, detail: 1 };
let mouseDownEvent = fireEvent(element, 'mousedown', options);

if (!isWindow(element) && !mouseDownEvent?.defaultPrevented) {
Expand All @@ -30,6 +31,8 @@ export function __doubleClick__(

fireEvent(element, 'mouseup', options);
fireEvent(element, 'click', options);

options = { ...options, detail: 2 };
fireEvent(element, 'mousedown', options);
fireEvent(element, 'mouseup', options);
fireEvent(element, 'click', options);
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/dom/click-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ module('DOM Helper: click', function (hooks) {
'clientY',
'button',
'buttons',
'detail',
]);

await click(element, { clientX: 13, clientY: 17, button: 2 });

assert.verifySteps([
'mousedown 13 17 2 1',
'mouseup 13 17 2 1',
'click 13 17 2 1',
'mousedown 13 17 2 1 1',
'mouseup 13 17 2 1 1',
'click 13 17 2 1 1',
]);
});

Expand Down
15 changes: 8 additions & 7 deletions tests/unit/dom/double-click-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,19 @@ module('DOM Helper: doubleClick', function (hooks) {
'clientY',
'button',
'buttons',
'detail',
]);

await doubleClick(element, { clientX: 13, clientY: 17, button: 1 });

assert.verifySteps([
'mousedown 13 17 1 1',
'mouseup 13 17 1 1',
'click 13 17 1 1',
'mousedown 13 17 1 1',
'mouseup 13 17 1 1',
'click 13 17 1 1',
'dblclick 13 17 1 1',
'mousedown 13 17 1 1 1',
'mouseup 13 17 1 1 1',
'click 13 17 1 1 1',
'mousedown 13 17 1 1 2',
'mouseup 13 17 1 1 2',
'click 13 17 1 1 2',
'dblclick 13 17 1 1 2',
]);
});
});
Expand Down