bug(cdkDrag): using cdkDragConstrainPosition causes erratic behavior
See original GitHub issueIs 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:
- Created a year ago
- Comments:15 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.This bug also seems to impact other parts of cdkDrag. Specifically when
cdkDragConstrainPosition
when used withcdkDragBoundary
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
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