Skip to content

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

Closed

Description

@Raphyyy

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

Activity

  1. added
    needs triage
    on Feb 13, 2022
  2. Raphyyy commented on Feb 13, 2022

    @Raphyyy
    Author

    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

  3. Raphyyy commented on Feb 13, 2022

    @Raphyyy
    Author

    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.

  4. self-assigned this
    on Feb 13, 2022
  5. added
    P3
    and removed
    needs triage
    on Feb 13, 2022
  6. added a commit that references this issue on Feb 13, 2022
    4815325
  7. crisbeto commented on Feb 13, 2022

    @crisbeto
    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;
    }
  8. Raphyyy commented on Feb 13, 2022

    @Raphyyy
    Author

    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 ?

  9. crisbeto commented on Feb 13, 2022

    @crisbeto
    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
    }]
    
  10. Raphyyy commented on Feb 13, 2022

    @Raphyyy
    Author

    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)

  11. crisbeto commented on Feb 13, 2022

    @crisbeto
    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.

  12. Raphyyy commented on Feb 14, 2022

    @Raphyyy
    Author

    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

  13. added a commit that references this issue on Feb 14, 2022
    5686262
  14. crisbeto commented on Feb 14, 2022

    @crisbeto
    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.

  15. added a commit that references this issue on Feb 14, 2022
    5164cc1
  16. Raphyyy commented on Feb 14, 2022

    @Raphyyy
    Author

    Nice thanks @crisbeto, works great on my side

  17. added 2 commits that reference this issue on Feb 17, 2022
    761f5fd
    81898ca
  18. angular-automatic-lock-bot commented on Mar 20, 2022

    @angular-automatic-lock-bot

    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.

  19. locked and limited conversation to collaborators on Mar 20, 2022
  20. added a commit that references this issue on Apr 3, 2022
    43feec1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: cdk/drag-drop

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions