You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem comes up with you mix together drag-and-drop and virtual scroll functionality. Here's the stackblitz that demonstrates the problem. I've painted the placeholder element into green.
I've done a lot of debugging to figure out the cause of the problem and I'll describe my findings below.
Steps to reproduce:
Configure component view to use both drag-and-drop and virtual scrolling
A draggable item is always rendered where I keep a mouse pointer.
Actual Behavior
As new elements are being rendered to the DOM, the draggable item loses its position and either disappears or starts jumping in the list.
Environment
Angular: 9.0.5
CDK/Material: 9.2.0
Browser(s): Chrome
Operating System (e.g. Windows, macOS, Ubuntu): Windows
Demo of the problem:
My investigation
The cause of the problem seems to be the new items that are being rendered. Once an item is added to the DOM, the CdkDrag directive attached to it registers itself within a drop list container. This in turn leads to the withItems method being triggered on the drop container list:
As the callstack unfolds, the cacheItemPositions method is called. The problem is that inside this method all current item positions (offsets) are reset to 0. If you add a logging to the method before and after this._this._itemPositions are updated:
maxkoretskyi
changed the title
bug(drag-drop): Draggable item loses its position when new list item is rendered in the DOM as a result of virtual scrolling
bug(drag-drop + virtual scroll): Draggable item loses its position when new list item is rendered in the DOM as a result of virtual scrolling
Apr 6, 2020
Using the drag&drop module together with infinite scrolling isn't supported, because we have some internal assumptions that all elements will be in the DOM. Closing the issue supporting it would require a major refactor and potentially a breaking public API change.
@crisbeto I am wondering when you said it isn't supported are you specifically referring to angular 9? the reason being i was able to accomplish this by the following code below:
<cdk-virtual-scroll-viewport itemSize="50" class="viewport"> <div cdkDropList (cdkDropListDropped)="onDrop($event)"> <div *cdkVirtualFor="let i of numbers" cdkDrag> {{i}} </div> </div> </cdk-virtual-scroll-viewport>
but when i used this line of code below am getting the same issue @maxkoretskyi is getting.
Reproduction
The problem comes up with you mix together drag-and-drop and virtual scroll functionality. Here's the stackblitz that demonstrates the problem. I've painted the placeholder element into green.
I've done a lot of debugging to figure out the cause of the problem and I'll describe my findings below.
Steps to reproduce:
Expected Behavior
A draggable item is always rendered where I keep a mouse pointer.
Actual Behavior
As new elements are being rendered to the DOM, the draggable item loses its position and either disappears or starts jumping in the list.
Environment
Demo of the problem:
My investigation
The cause of the problem seems to be the new items that are being rendered. Once an item is added to the DOM, the
CdkDrag
directive attached to it registers itself within a drop list container. This in turn leads to thewithItems
method being triggered on the drop container list:As the callstack unfolds, the cacheItemPositions method is called. The problem is that inside this method all current item positions (offsets) are reset to 0. If you add a logging to the method before and after
this._this._itemPositions
are updated:this is what the console shows:
This leads to a placeholder element lose current position and start jumping in the list.
I'm happy to make a PR to fix it, if I get guidance on the best way to address this problem.
The text was updated successfully, but these errors were encountered: