Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/cdk/drag-drop/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,30 @@ describe('CdkDrag', () => {
.toEqual(['Zero', 'One', 'Two', 'Three']);
}));

it('should not throw if the `touches` array is empty', fakeAsync(() => {
const fixture = createComponent(DraggableInDropZone);
fixture.detectChanges();
const item = fixture.componentInstance.dragItems.toArray()[1].element.nativeElement;

dispatchTouchEvent(item, 'touchstart');
fixture.detectChanges();

dispatchTouchEvent(document, 'touchmove');
fixture.detectChanges();

dispatchTouchEvent(document, 'touchmove', 50, 50);
fixture.detectChanges();

expect(() => {
const endEvent = createTouchEvent('touchend', 50, 50);
Object.defineProperty(endEvent, 'touches', {get: () => []});

dispatchEvent(document, endEvent);
fixture.detectChanges();
}).not.toThrow();

}));

});

describe('in a connected drop container', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/cdk/drag-drop/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {

/** Determines the point of the page that was touched by the user. */
private _getPointerPositionOnPage(event: MouseEvent | TouchEvent): Point {
const point = this._isTouchEvent(event) ? event.touches[0] : event;
// `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
const point = this._isTouchEvent(event) ? (event.touches[0] || event.changedTouches[0]) : event;

return {
x: point.pageX - this._scrollPosition.left,
Expand Down