Skip to content

Commit 5164406

Browse files
author
Timon Krebs
committed
feat(cdk/drag-drop): added dropPosition also to CdkDragEnd
1 parent eee8300 commit 5164406

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/cdk/drag-drop/directives/drag.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,11 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
459459
});
460460

461461
ref.ended.subscribe(event => {
462-
this.ended.emit({source: this, distance: event.distance});
462+
this.ended.emit({
463+
source: this,
464+
distance: event.distance,
465+
dropPosition: event.dropPosition
466+
});
463467

464468
// Since all of these events run outside of change detection,
465469
// we need to ensure that everything is marked correctly.

src/cdk/drag-drop/drag-events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface CdkDragEnd<T = any> {
2727
source: CdkDrag<T>;
2828
/** Distance in pixels that the user has dragged since the drag sequence started. */
2929
distance: {x: number, y: number};
30+
/** Position where the pointer was when the item was dropped */
31+
dropPosition: {x: number, y: number};
3032
}
3133

3234
/** Event emitted when the user moves an item into a new drop container. */

src/cdk/drag-drop/drag-ref.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class DragRef<T = any> {
294294
released = new Subject<{source: DragRef}>();
295295

296296
/** Emits when the user stops dragging an item in the container. */
297-
ended = new Subject<{source: DragRef, distance: Point}>();
297+
ended = new Subject<{source: DragRef, distance: Point, dropPosition: Point}>();
298298

299299
/** Emits when the user has moved the item into a new container. */
300300
entered = new Subject<{container: DropListRef, item: DragRef, currentIndex: number}>();
@@ -765,11 +765,13 @@ export class DragRef<T = any> {
765765
// the user starts dragging the item, its position will be calculated relatively
766766
// to the new passive transform.
767767
this._passiveTransform.x = this._activeTransform.x;
768+
const pointerPosition = this._getPointerPositionOnPage(event);
768769
this._passiveTransform.y = this._activeTransform.y;
769770
this._ngZone.run(() => {
770771
this.ended.next({
771772
source: this,
772-
distance: this._getDragDistance(this._getPointerPositionOnPage(event))
773+
distance: this._getDragDistance(pointerPosition),
774+
dropPosition: pointerPosition
773775
});
774776
});
775777
this._cleanupCachedDimensions();
@@ -911,11 +913,11 @@ export class DragRef<T = any> {
911913
const container = this._dropContainer!;
912914
const currentIndex = container.getItemIndex(this);
913915
const pointerPosition = this._getPointerPositionOnPage(event);
914-
const distance = this._getDragDistance(this._getPointerPositionOnPage(event));
916+
const distance = this._getDragDistance(pointerPosition);
915917
const isPointerOverContainer = container._isOverContainer(
916918
pointerPosition.x, pointerPosition.y);
917919

918-
this.ended.next({source: this, distance});
920+
this.ended.next({source: this, distance, dropPosition: pointerPosition});
919921
this.dropped.next({
920922
item: this,
921923
currentIndex,

tools/public_api_guard/cdk/drag-drop.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export interface CdkDragEnd<T = any> {
8181
x: number;
8282
y: number;
8383
};
84+
dropPosition: {
85+
x: number;
86+
y: number;
87+
};
8488
source: CdkDrag<T>;
8589
}
8690

0 commit comments

Comments
 (0)