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

bug(@angular/cdk/drag-drop): Grabbing a cdkDrag element with underlying link element cause the link to be grabbed with css transition #24403

Closed
1 task
Raphyyy opened this issue Feb 13, 2022 · 11 comments · Fixed by #24404
Assignees
Labels
area: cdk/drag-drop P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@Raphyyy
Copy link

Raphyyy commented Feb 13, 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

No response

Description

When grabbing an element that just have been dropped, you will get the underlying link to be grabbed instead of the cdkDrag element if you drag from the link.
It only appears if used CSS transition on transform to make smoother moves, so I think the issue is happening when the CSS animation has not ended.
Attaching cdkDrag to a parent element instead of setting it on the element doesn't change a thing. (see difference between the "To do" cdkDropList and the "Done" cdkDropList.

grab_bug

Maybe related issue : https://stackoverflow.com/questions/68924215/cdkdrag-sometimes-grabs-uderlying-link-element

Note : the attached stackblitz run Angular 12.0.0, but the issue also appears on my local with Angular 13.2.2.

Reproduction

Steps to reproduce:

  1. https://stackblitz.com/edit/angular-pqknrn-x92xnv?file=src/app/cdk-drag-drop-connected-sorting-group-example.html
  2. Grab an element, drop it somewhere and quickly regrab-it from the link

Expected Behavior

The underlying link should not be dragged

Actual Behavior

The underlying link is dragged instead of the cdkDrag element

Environment

  • Angular: 13.2.2
  • CDK/Material: 13.2.2
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
@Raphyyy Raphyyy added the needs triage This issue needs to be triaged by the team label Feb 13, 2022
@Raphyyy
Copy link
Author

Raphyyy commented Feb 13, 2022

It looks like the issue can also appears sometimes without having to drop and redrag the same item immediately.
Removing the css transition also seems to fix it

grab_bug

@Raphyyy
Copy link
Author

Raphyyy commented Feb 13, 2022

There is a workaround : Simply add draggable="false" to the element to prevent the link from being dragged.
However, the cdk dragging still do not trigger when it happens.
Setting user-select: none do not fix it.

@crisbeto crisbeto self-assigned this Feb 13, 2022
@crisbeto crisbeto added area: cdk/drag-drop has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Feb 13, 2022
crisbeto added a commit to crisbeto/material2 that referenced this issue Feb 13, 2022
Removes the pointer events from the drag placeholder so that the user can't interact with it while the preview is animating.

Fixes angular#24403.
@crisbeto
Copy link
Member

I couldn't quite reproduce the issue without slowing down the preview transition a lot, but my theory is that the dragging is actually happening on the placeholder element behind the preview. I have #24404 out to fix it, but can you double-check that adding the following CSS styles resolve the issue for you?

.cdk-drag-placeholder {
  pointer-events: none;
}

@Raphyyy
Copy link
Author

Raphyyy commented Feb 13, 2022

Thanks @crisbeto, unfortunately this doesn't fix it on my side : https://stackblitz.com/edit/angular-pqknrn-x92xnv?file=src/app/cdk-drag-drop-connected-sorting-group-example.css
grab_bug
Adding this doesn't fix it neither :

.cdk-drag-placeholder * {
  pointer-events: none;
}

I kept the same 250ms transition. Did you try to quickly regrab the item before the transition end ?

@crisbeto
Copy link
Member

Yes, I can't reproduce it at all with the 250ms transition on either Chrome or Firefox. I could reproduce it if I bump up the transition to 2500ms, but the pointer-events: none on the placeholder fixed it for me. The only other cause I can see is that by default we have some logic which makes it so that you have to drag at least 5px before dragging starts so that dragging isn't mistaken for clicking. You can try to reduce it by adding the following to the component:

providers: [{
  provide: CDK_DRAG_CONFIG,
  dragStartThreshold: 0
}]

@Raphyyy
Copy link
Author

Raphyyy commented Feb 13, 2022

Added this to component :

  providers: [{
    provide: CDK_DRAG_CONFIG,
    useValue: {
      dragStartThreshold: 0
    } 
  }],

Doesn't fix it unfortunately. Tested the issue on another Windows 11 and got the same result (both in a clean environment browser)

@crisbeto
Copy link
Member

I'm testing on a Windows machine as well so it's weird that it doesn't happen for me. One more thing worth trying is to expand the CSS from above to:

.cdk-drag-placeholder {
  pointer-events: none;
  touch-action: none;
  -webkit-user-drag: none;
  use-select: none;
}

This is what we set on other elements in order to prevent native dragging interactions.

@Raphyyy
Copy link
Author

Raphyyy commented Feb 14, 2022

Ok so it looks like the issue happens when you mousedown the link on the .cdk-drag-preview while it is still moving, wait for the transition to end, and then start moving the mouse.
grab_bug
The yellow dot tells when I hold left click
That's why you might missed it with 2500ms
Edit: The css you send earlier doesn't fix it unfortunately

crisbeto added a commit to crisbeto/material2 that referenced this issue Feb 14, 2022
Removes the pointer events from the drag placeholder so that the user can't interact with it while the preview is animating.

Fixes angular#24403.
@crisbeto
Copy link
Member

Thanks, I was able to reproduce it now, albeit not consistently. I've pushed another fix to #24404. You can try it out by adding (dragstart)="$event.preventDefault()" to the cdkDrag elements.

crisbeto added a commit to crisbeto/material2 that referenced this issue Feb 14, 2022
Removes the pointer events from the drag placeholder so that the user can't interact with it while the preview is animating.

Fixes angular#24403.
@Raphyyy
Copy link
Author

Raphyyy commented Feb 14, 2022

Nice thanks @crisbeto, works great on my side

@Raphyyy Raphyyy closed this as completed Feb 14, 2022
@Raphyyy Raphyyy reopened this Feb 14, 2022
andrewseguin pushed a commit that referenced this issue Feb 17, 2022
Removes the pointer events from the drag placeholder so that the user can't interact with it while the preview is animating.

Fixes #24403.
andrewseguin pushed a commit that referenced this issue Feb 17, 2022
Removes the pointer events from the drag placeholder so that the user can't interact with it while the preview is animating.

Fixes #24403.

(cherry picked from commit 761f5fd)
@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 Mar 20, 2022
forsti0506 pushed a commit to forsti0506/components that referenced this issue Apr 3, 2022
Removes the pointer events from the drag placeholder so that the user can't interact with it while the preview is animating.

Fixes angular#24403.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/drag-drop P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants