Skip to content

Drag and Drop positions draggable element incorrectly when style.margin-left is set #16171

@shershey

Description

@shershey

Reproduction

The following stackblitz demonstrated the problem:

https://stackblitz.com/edit/angular-drag-and-drop-bug

Steps to reproduce:

  1. Copied https://material.angular.io/cdk/drag-drop/overview#reordering-lists to stackblitz
  2. Added marginLeft style to the draggable elements.

When using draggable elements outside of cdkDropList, the problem does not occur.

Expected Behavior

I was expecting that the dragged element would not jump suddenly to the right when I start dragging.

Actual Behavior

The dragged element jumps to the right.

In looking at this line, it appears that the style is copied from the draggable element when creating the preview element. That in combination with the transform applies the marign-left twice (sort of). I was hoping that maybe I could work around this by using cdkDragFreeDragPosition instead of setting marginLeft, but it seems cdkDragFreeDragPosition doesn't work when used inside cdkDropList. This bug seems to be similar to #13107 but I believe that bug is closed and the fix does not seem to help here.

I'd love to know if there are ways I can work around this bug for now.

Environment

Metadata

Metadata

Assignees

Labels

GThis is is related to a Google internal issueP3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions