File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -1187,6 +1187,27 @@ describe('CdkDrag', () => {
1187
1187
expect ( drag . rootElementSelector ) . toBe ( '.root' ) ;
1188
1188
} ) ) ;
1189
1189
1190
+ it ( 'should not throw if touches and changedTouches are empty' , fakeAsync ( ( ) => {
1191
+ const fixture = createComponent ( StandaloneDraggable ) ;
1192
+ fixture . detectChanges ( ) ;
1193
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
1194
+
1195
+ startDraggingViaTouch ( fixture , dragElement ) ;
1196
+ continueDraggingViaTouch ( fixture , 50 , 100 ) ;
1197
+
1198
+ const event = createTouchEvent ( 'touchend' , 50 , 100 ) ;
1199
+ Object . defineProperties ( event , {
1200
+ touches : { get : ( ) => [ ] } ,
1201
+ changedTouches : { get : ( ) => [ ] }
1202
+ } ) ;
1203
+
1204
+ expect ( ( ) => {
1205
+ dispatchEvent ( document , event ) ;
1206
+ fixture . detectChanges ( ) ;
1207
+ tick ( ) ;
1208
+ } ) . not . toThrow ( ) ;
1209
+ } ) ) ;
1210
+
1190
1211
} ) ;
1191
1212
1192
1213
describe ( 'draggable with a handle' , ( ) => {
Original file line number Diff line number Diff line change @@ -1034,9 +1034,16 @@ export class DragRef<T = any> {
1034
1034
1035
1035
/** Determines the point of the page that was touched by the user. */
1036
1036
private _getPointerPositionOnPage ( event : MouseEvent | TouchEvent ) : Point {
1037
- // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
1038
- const point = isTouchEvent ( event ) ? ( event . touches [ 0 ] || event . changedTouches [ 0 ] ) : event ;
1039
1037
const scrollPosition = this . _getViewportScrollPosition ( ) ;
1038
+ const point = isTouchEvent ( event ) ?
1039
+ // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
1040
+ // Also note that on real devices we're guaranteed for either `touches` or `changedTouches`
1041
+ // to have a value, but Firefox in device emulation mode has a bug where both can be empty
1042
+ // for `touchstart` and `touchend` so we fall back to a dummy object in order to avoid
1043
+ // throwing an error. The value returned here will be incorrect, but since this only
1044
+ // breaks inside a developer tool and the value is only used for secondary information,
1045
+ // we can get away with it. See https://bugzilla.mozilla.org/show_bug.cgi?id=1615824.
1046
+ ( event . touches [ 0 ] || event . changedTouches [ 0 ] || { pageX : 0 , pageY : 0 } ) : event ;
1040
1047
1041
1048
return {
1042
1049
x : point . pageX - scrollPosition . left ,
You can’t perform that action at this time.
0 commit comments