question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(cdkDrag): using cdkDragConstrainPosition causes erratic behavior

See original GitHub issue

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.3.9

Description

cdkDrag works normally with box and axis constraints, but as soon as cdkDragConstrainPosition is used, the dragged element incorrectly jumps a few pixels down the y-axis.

Reproduction

Please refer to the reproduction:

https://angular-ivy-iry1fk.stackblitz.io

https://stackblitz.com/edit/angular-ivy-iry1fk?file=package.json

Expected Behavior

The dragged element should only move horizontally and not jump down the y-axis.

Actual Behavior

The element jumps a few pixels down.

Environment

  • Angular: 14.0.0
  • CDK/Material: 14.0.0
  • Browser(s): Chrome / Firefox
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
crisbetocommented, Jul 26, 2022

You’d have to offset it based on the position at which the user picked up the element, which I now realize isn’t possible to read. I’ve opened up #25341 to expose it within the constrainPosition callback.

0reactions
HuntosShuntoscommented, Dec 17, 2022

This bug also seems to impact other parts of cdkDrag. Specifically when cdkDragConstrainPosition when used with cdkDragBoundary also seems to have erratic behavior.

Reproduction See below https://angular-ivy-9unppr.stackblitz.io https://stackblitz.com/edit/angular-ivy-9unppr?file=src/app/app.component.html

Environment

Angular: 15.0.3
CDK/Material: 15.0.3
Browser(s): Chrome / Firefox
Operating System (e.g. Windows, macOS, Ubuntu): Windows

Expected Behavior Should stay within the drag boundary and be able to go to the edges of the boundary

Actual Behavior Seems that the drag boundary arbitrarily moves

Read more comments on GitHub >

github_iconTop Results From Across the Web

CdkDrag moves way too fast - Stack Overflow
I imagine you has two functions that move the element (click) and (drag). You can has a variable "onDrag", so you can has...
Read more >
5 Things I wish I knew about the CDK's Drag & Drop
I've been trying to do cool things with the CDK and cdkDragDrop for ... Here's a few of the reasons I ended up...
Read more >
UNPKG - @angular/cdk
ELEMENT_NODE) {\n throw Error(`cdkDrag must be attached to an element node. ... For some reason the Firefox property is in PascalCase.
Read more >
Drag and Drop | Angular Material
The @angular/cdk/drag-drop module provides you with a way to easily and ... You can now add the cdkDrag directive to elements to make...
Read more >
Angular Material Drag and Drop – Strengths and Limitations
In an existing angular application with the CDK installed, import the DragDropModule from @angular/cdk/drag-drop into the appropriate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found