File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -1895,6 +1895,30 @@ describe('CdkDrag', () => {
18951895 . toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
18961896 } ) ) ;
18971897
1898+ it ( 'should not throw if the `touches` array is empty' , fakeAsync ( ( ) => {
1899+ const fixture = createComponent ( DraggableInDropZone ) ;
1900+ fixture . detectChanges ( ) ;
1901+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1902+
1903+ dispatchTouchEvent ( item , 'touchstart' ) ;
1904+ fixture . detectChanges ( ) ;
1905+
1906+ dispatchTouchEvent ( document , 'touchmove' ) ;
1907+ fixture . detectChanges ( ) ;
1908+
1909+ dispatchTouchEvent ( document , 'touchmove' , 50 , 50 ) ;
1910+ fixture . detectChanges ( ) ;
1911+
1912+ expect ( ( ) => {
1913+ const endEvent = createTouchEvent ( 'touchend' , 50 , 50 ) ;
1914+ Object . defineProperty ( endEvent , 'touches' , { get : ( ) => [ ] } ) ;
1915+
1916+ dispatchEvent ( document , endEvent ) ;
1917+ fixture . detectChanges ( ) ;
1918+ } ) . not . toThrow ( ) ;
1919+
1920+ } ) ) ;
1921+
18981922 } ) ;
18991923
19001924 describe ( 'in a connected drop container' , ( ) => {
Original file line number Diff line number Diff line change @@ -790,7 +790,8 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
790790
791791 /** Determines the point of the page that was touched by the user. */
792792 private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
793- const point = this . _isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
793+ // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
794+ const point = this . _isTouchEvent ( event ) ? ( event . touches [ 0 ] || event . changedTouches [ 0 ] ) : event ;
794795
795796 return {
796797 x : point . pageX - this . _scrollPosition . left ,
You can’t perform that action at this time.
0 commit comments