Skip to content

Commit 664ef4c

Browse files
crisbetojelbourn
authored andcommitted
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.
1 parent 6575ade commit 664ef4c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cdk/drag-drop/drop.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
314314

315315
/** Refreshes the position cache of the items and sibling containers. */
316316
private _cachePositions() {
317+
const isHorizontal = this.orientation === 'horizontal';
317318
this._positionCache.items = this._activeDraggables
318319
.map(drag => {
319320
const elementToMeasure = this._dragDropRegistry.isDragging(drag) ?
@@ -340,7 +341,10 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
340341
}
341342
};
342343
})
343-
.sort((a, b) => a.clientRect.top - b.clientRect.top);
344+
.sort((a, b) => {
345+
return isHorizontal ? a.clientRect.left - b.clientRect.left :
346+
a.clientRect.top - b.clientRect.top;
347+
});
344348

345349
this._positionCache.siblings = coerceArray(this.connectedTo)
346350
.map(drop => typeof drop === 'string' ? this._dragDropRegistry.getDropContainer(drop)! : drop)

0 commit comments

Comments
 (0)