fix(drag-drop): incorrectly calculating index when sorting horizontally (#13082)

Fixes the list index not being calculated correctly, because the items are being sorted in memory based on their `top` position, even though the dragging is horizontal.

Fixes #13072.
This commit is contained in:
Kristiyan Kostadinov
2018-09-12 00:12:47 +02:00
committed by Jeremy Elbourn
parent 6575ade81a
commit 664ef4c9d3
+5 -1
View File
@@ -314,6 +314,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
/** Refreshes the position cache of the items and sibling containers. */
private _cachePositions() {
const isHorizontal = this.orientation === 'horizontal';
this._positionCache.items = this._activeDraggables
.map(drag => {
const elementToMeasure = this._dragDropRegistry.isDragging(drag) ?
@@ -340,7 +341,10 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
}
};
})
.sort((a, b) => a.clientRect.top - b.clientRect.top);
.sort((a, b) => {
return isHorizontal ? a.clientRect.left - b.clientRect.left :
a.clientRect.top - b.clientRect.top;
});
this._positionCache.siblings = coerceArray(this.connectedTo)
.map(drop => typeof drop === 'string' ? this._dragDropRegistry.getDropContainer(drop)! : drop)