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

Dispatching MouseEvents is broken after upgrade from version 13.1.2 to 13.1.3 #24577

Closed
1 task done
HWouters opened this issue Mar 11, 2022 · 18 comments
Closed
1 task done
Labels
area: cdk/drag-drop needs: clarification The issue does not contain enough information for the team to determine if it is a real bug P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@HWouters
Copy link

HWouters commented Mar 11, 2022

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

13.1.2

Description

After upgrading from 13.1.2 to 13.1.3 our drag and drop tests are failing. It looks like nothing is happening and the events are ignored.
We are using Cypress in similar approach to here: https://stackoverflow.com/questions/55361499/how-to-implement-drag-and-drop-in-cypress-test/55436989#55436989

Reproduction

Steps to reproduce:
Upgrade from 13.1.2 to 13.1.3

Expected Behavior

Able to test drag drop behavior by disptaching mouseevents

Actual Behavior

Mouse events are ignored

Environment

  • Angular: 13
  • Browser(s): chrome
@HWouters HWouters added the needs triage This issue needs to be triaged by the team label Mar 11, 2022
@crisbeto
Copy link
Member

There haven't been any fundamental changes in cdk/drag-drop in a while and I don't see any at all between 13.1.2 and 13.1.3. Could it be something that has changed in your setup?

@crisbeto crisbeto added needs: clarification The issue does not contain enough information for the team to determine if it is a real bug area: cdk/drag-drop and removed needs triage This issue needs to be triaged by the team labels Mar 15, 2022
@HWouters
Copy link
Author

@crisbeto I don't think so. I could really pinpoint the problem to this specific version update.

@HWouters
Copy link
Author

@crisbeto the problem is probably not in drag drop, but in handling mouseevents. I saw some changes related to that, but don't know if they are causing the issue.

@crisbeto
Copy link
Member

Handling of mouse events by which module?

@HWouters
Copy link
Author

I don't know the codebase and I might be completely wrong, but I was referring to #23493

@crisbeto
Copy link
Member

If #23493 broke anything, it would've only prevented focus indication from showing up on some components. It wouldn't affect any other event listeners.

@HWouters
Copy link
Author

Then it has to be something else, bumping the installed version from 13.1.2 to 13.1.3 (@angular/cdk & @angular/material) breaks our drag/drop tests. It looks like mouseevents are ingored, nothing moves anymore after the update.

@crisbeto
Copy link
Member

Is it possible that Cypress changed how they're dispatching events?

@HWouters
Copy link
Author

No, I narrowed it down to only this version update. If I install 13.1.2 it works, if I install 13.1.3 it doesn't.

@crisbeto
Copy link
Member

I'm looking through the changelog between 13.1.2 and 13.1.3, and I really don't see anything that could break event handling.

@HWouters
Copy link
Author

@crisbeto thank you for looking into this. I double checked it again, but it is really this version. I could narrow it even further to only @angular/cdk package. Here is a screenshot of my changes: only updating this single version breaks drag an drop testing.
image

@HWouters
Copy link
Author

HWouters commented Mar 17, 2022

@crisbeto I think the issue is related to #23493. If I add buttons: 1 to my mouse events it works.

element.dispatchEvent(<any>new MouseEvent('mousedown', { buttons: 1, bubbles: true }));
element.dispatchEvent(<any>new MouseEvent('mousemove', { buttons: 1, clientX: 10, clientY: 0 }));
element.dispatchEvent(<any>new MouseEvent('mousemove', { buttons: 1, clientX: rect.x + 10, clientY: rect.y + 10 }));
element.dispatchEvent(<any>new MouseEvent('mouseup', { buttons: 1 }));

original doesn't work:

element.dispatchEvent(<any>new MouseEvent('mousedown', { bubbles: true }));
element.dispatchEvent(<any>new MouseEvent('mousemove', { clientX: 10, clientY: 0 }));
element.dispatchEvent(<any>new MouseEvent('mousemove', { clientX: rect.x + 10, clientY: rect.y + 10 }));
element.dispatchEvent(<any>new MouseEvent('mouseup'));

@crisbeto
Copy link
Member

Interesting, I wonder if your test depends upon the extra change detection that is triggered by focus monitor. If that's the case, you may end up broken again by #15077 which is close to being merged.

@miluoshi
Copy link

miluoshi commented Apr 4, 2022

I can confirm that it also broke our Cypress tests related to drag-n-drop after upgrading from 13.1.2 to 13.1.3 without any other changes.

@jobinsam
Copy link

jobinsam commented Aug 17, 2022

This upgrade broke our drag & drop tests too. Was wondering why these tests are not failing.

https://github.com/angular/components/blob/4d723d7114a33fa8772163e885547e50227dcbeb/src/cdk/drag-drop/directives/drag.spec.ts

@andrewseguin andrewseguin added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Jun 1, 2023
@miluoshi
Copy link

miluoshi commented Nov 23, 2023

I've just discovered, that from version @angular/[email protected] you need to set both of those properties (buttons and detail) when creating MouseEvent:

new MouseEvent(eventName, {
  bubbles: true,
  buttons: 1, // Primary button (https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons#value)
  cancelable: true,
  clientX: coords.x,
  clientY: coords.y,
  detail: 1, // This needs to be added since @angular/[email protected]
});

Caused by this change #28029

@crisbeto
Copy link
Member

Closing since there appears to be workaround.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/drag-drop needs: clarification The issue does not contain enough information for the team to determine if it is a real bug P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

5 participants