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

cdk-drag: incorrect position when dragging child element #13107

Closed
skreborn opened this issue Sep 13, 2018 · 3 comments · Fixed by #13111
Closed

cdk-drag: incorrect position when dragging child element #13107

skreborn opened this issue Sep 13, 2018 · 3 comments · Fixed by #13111
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@skreborn
Copy link

Bug, feature request, or proposal:

When a cdk-drag is within a cdk-drop, the cdk-drag element will jump to an incorrectly offset position when the mouse is first moved, given that the user drags this element using a child. The offset is always the same as the child element's offset from the parent cdk-drag container (for example, padding of the parent or margin of the child).

What is the expected behavior?

The cdk-drag element should always stay at the same position relative to the cursor.

What is the current behavior?

The cdk-drag element jumps towards the bottom right when the child element is offset from its parent.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-92bnjh?file=app/cdk-drag-drop-sorting-example.html

Drag using "FIRST", "LAST" or the movie title to see the incorrect behavior. Dragging by the parent element results in the correct and desired behavior.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular Material: 7.0.0-beta.0

@skreborn
Copy link
Author

skreborn commented Sep 13, 2018

It seems like this is due to the fact that _getPointerPositionInElement reports the incorrect offset by using event.offsetX and event.offsetY - both of which refer to the cursor's offset from the event originator (the child element) instead of the desired parent.

@skreborn
Copy link
Author

skreborn commented Sep 13, 2018

Copying over the calculation from the touch event seems to result in the correct behavior.

const x = (this._isTouchEvent(event) ? event.targetTouches[0] : event).pageX - referenceRect.left - this._scrollPosition.left;
const y = (this._isTouchEvent(event) ? event.targetTouches[0] : event).pageY - referenceRect.top - this._scrollPosition.top;

Can anyone verify this?

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr labels Sep 13, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 13, 2018
…nt, in some cases

Fixes `CdkDrag` not calculating the pointer position inside the element correctly, if dragging started from inside another element within the draggable.

Fixes angular#13107.
jelbourn pushed a commit that referenced this issue Sep 13, 2018
…nt, in some cases (#13111)

Fixes `CdkDrag` not calculating the pointer position inside the element correctly, if dragging started from inside another element within the draggable.

Fixes #13107.
@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 Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
2 participants