-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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(cdkDrag): using cdkDragConstrainPosition causes erratic behavior #25154
Comments
This is likely the result of #25061 which made it so that the position constrain function determines the top/left coordinates of the element. You see it jump down a little because the "normal" dragging behavior also accounts for the pick up position within the element whereas the one returned from the constrain callback is the top/left. This is how the constrain position input was intended to work, but a poorly written unit test meant that it had broken at some point and we hadn't noticed. |
I must admit that I at this point cannot figure out how to use the I understand that the given point is now where the mouse is dragging on the page, and just returning the point will make the element render with the top/left at exactly that point. But even if I just offset that by say 10px, it seems to make the whole drag/drop experience act weird. Maybe it is just missing documentation / information about how one is expected to implement the constraining logic I'm missing, but to me, the old behavior was at least a bit more intuitive. |
Not sure I understand. Does that mean that it actually is a bug that needs fixing in cdkDrag? Or should I adjust my code to work with the new logic? |
The idea of that function has always been that the |
Ah okay! Thanks. |
@crisbeto I have the same problem, basically I want to use it for a split view, so I lock the axis in one direction and also want to constrain the position in the other direction. This is now next to impossible and is preventing us from updating to Angular 14. With Angular 13 it worked perfectly. This is a simple example showing the problem: With axes locked, the constraint causes erratic behavior. |
So the (not well documented) assumption is that if you're using In retrospect, |
Makes sense, I'll try that, thank you! |
Works perfect. |
Can you provide an example how to calcuate returning point coordinates so it will drag the item without jumping to top left corner? So basicply the constrainPosition function will not do anything. From that point we can adjust the code for our needs. `constrainPosition(point: Point, dragRef: DragRef)
}` Thank you |
Exposes the pickup position within the element to the `constrainPosition` callback so that users can account for it in their calculations. Relates to angular#25154.
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 |
Watch out guys/gals, just spent 2 hours debugging why my dragged element jumps like crazy and the reason is that you receive user pointer position and you're supposed to return top left corner position. So I guess not much has changed and still have to use pickup position in the calculations. At least now I no longer have to calculate it but receive it as the last function. It would be nice to actually receive the top left corner point, apply limiting function and return top left corner point. |
@ioanes To get the top left corner from the point, you need to subtract the pickup position in draggable from the
You need to be on the latest version though, since @crisbeto added the pickup parameter a month ago. Before that, you had to calculate it yourself. |
This bug also seems to impact other parts of cdkDrag. Specifically when Reproduction Environment
Expected Behavior Actual Behavior |
Is there anything I/someone can do to get this moving forward somehow? Or at least get some clarification about what is going to happen with the strange behavior still seen in some cases. We are currently stuck building our own patched version using the old behavior before #25061 for our project, as we're using I am open to contribute in solving this if required. It seems the example of @HuntosShuntos is showing the problem we're having, which was introduced by #25061. If |
@mj3052 I haven't had time to look into this, because of different team priorities. I'd be open to reviewing and landing a fix though. |
i stumbled across this problem too, i thought i go crazy until i saw this issue! i cant move the element to the top left corner. (somehow its depending on where i click on the element). IMO, this is a huge issue and should get a higher priority. |
This is still blocking us from updating as well. We are running angular 15 with cdk 13 for now. |
I've tried to implement an initial fix in PR #27730. All tests seem to be passing. @crisbeto Let me know what needs to be done in order to get this further. I am not sure about how you guys normally use the dev-app, but I added two more cases in it (one using just the boundary and one combining the boundary with a constraint), to make sure it works in all cases. I can easily remove this if need be. |
@mj3052 Now working perfectly fine (tested in |
Closing since this should be fixed now. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is this a regression?
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
The text was updated successfully, but these errors were encountered: