File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -1782,6 +1782,30 @@ describe('CdkDrag', () => {
1782
1782
. toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
1783
1783
} ) ) ;
1784
1784
1785
+ it ( 'should not throw if the `touches` array is empty' , fakeAsync ( ( ) => {
1786
+ const fixture = createComponent ( DraggableInDropZone ) ;
1787
+ fixture . detectChanges ( ) ;
1788
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1789
+
1790
+ dispatchTouchEvent ( item , 'touchstart' ) ;
1791
+ fixture . detectChanges ( ) ;
1792
+
1793
+ dispatchTouchEvent ( document , 'touchmove' ) ;
1794
+ fixture . detectChanges ( ) ;
1795
+
1796
+ dispatchTouchEvent ( document , 'touchmove' , 50 , 50 ) ;
1797
+ fixture . detectChanges ( ) ;
1798
+
1799
+ expect ( ( ) => {
1800
+ const endEvent = createTouchEvent ( 'touchend' , 50 , 50 ) ;
1801
+ Object . defineProperty ( endEvent , 'touches' , { get : ( ) => [ ] } ) ;
1802
+
1803
+ dispatchEvent ( document , endEvent ) ;
1804
+ fixture . detectChanges ( ) ;
1805
+ } ) . not . toThrow ( ) ;
1806
+
1807
+ } ) ) ;
1808
+
1785
1809
} ) ;
1786
1810
1787
1811
describe ( 'in a connected drop container' , ( ) => {
Original file line number Diff line number Diff line change @@ -747,7 +747,8 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
747
747
748
748
/** Determines the point of the page that was touched by the user. */
749
749
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
750
- const point = this . _isTouchEvent ( event ) ? event . touches [ 0 ] : event ;
750
+ // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
751
+ const point = this . _isTouchEvent ( event ) ? ( event . touches [ 0 ] || event . changedTouches [ 0 ] ) : event ;
751
752
752
753
return {
753
754
x : point . pageX - this . _scrollPosition . left ,
You can’t perform that action at this time.
0 commit comments