mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Jeremy Elbourn
parent
6575ade81a
commit
664ef4c9d3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user