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 @@ -1895,6 +1895,30 @@ describe('CdkDrag', () => {
1895
1895
. toEqual ( [ 'Zero' , 'One' , 'Two' , 'Three' ] ) ;
1896
1896
} ) ) ;
1897
1897
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
+
1898
1922
} ) ;
1899
1923
1900
1924
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 {
790
790
791
791
/** Determines the point of the page that was touched by the user. */
792
792
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 ;
794
795
795
796
return {
796
797
x : point . pageX - this . _scrollPosition . left ,
You can’t perform that action at this time.
0 commit comments