@@ -18,6 +18,7 @@ import {
18
18
dispatchEvent ,
19
19
dispatchMouseEvent ,
20
20
dispatchTouchEvent ,
21
+ createTouchEvent ,
21
22
} from '@angular/cdk/testing' ;
22
23
import { Directionality } from '@angular/cdk/bidi' ;
23
24
import { CdkDrag , CDK_DRAG_CONFIG , CdkDragConfig } from './drag' ;
@@ -169,6 +170,25 @@ describe('CdkDrag', () => {
169
170
expect ( dragElement . style . transform ) . toBe ( 'translateY(-50%) translate3d(150px, 300px, 0px)' ) ;
170
171
} ) ) ;
171
172
173
+ it ( 'should prevent the `mousedown` action for native draggable elements' , fakeAsync ( ( ) => {
174
+ const fixture = createComponent ( StandaloneDraggable ) ;
175
+ fixture . detectChanges ( ) ;
176
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
177
+
178
+ dragElement . draggable = true ;
179
+
180
+ const mousedownEvent = createMouseEvent ( 'mousedown' , 50 , 50 ) ;
181
+ Object . defineProperty ( mousedownEvent , 'target' , { get : ( ) => dragElement } ) ;
182
+ spyOn ( mousedownEvent , 'preventDefault' ) . and . callThrough ( ) ;
183
+ dispatchEvent ( dragElement , mousedownEvent ) ;
184
+ fixture . detectChanges ( ) ;
185
+
186
+ dispatchMouseEvent ( document , 'mousemove' , 50 , 50 ) ;
187
+ fixture . detectChanges ( ) ;
188
+
189
+ expect ( mousedownEvent . preventDefault ) . toHaveBeenCalled ( ) ;
190
+ } ) ) ;
191
+
172
192
} ) ;
173
193
174
194
describe ( 'touch dragging' , ( ) => {
@@ -244,6 +264,25 @@ describe('CdkDrag', () => {
244
264
dispatchTouchEvent ( document , 'touchend' ) ;
245
265
fixture . detectChanges ( ) ;
246
266
} ) ) ;
267
+
268
+ it ( 'should not prevent `touchstart` action for native draggable elements' , fakeAsync ( ( ) => {
269
+ const fixture = createComponent ( StandaloneDraggable ) ;
270
+ fixture . detectChanges ( ) ;
271
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
272
+
273
+ dragElement . draggable = true ;
274
+
275
+ const touchstartEvent = createTouchEvent ( 'touchstart' , 50 , 50 ) ;
276
+ Object . defineProperty ( touchstartEvent , 'target' , { get : ( ) => dragElement } ) ;
277
+ spyOn ( touchstartEvent , 'preventDefault' ) . and . callThrough ( ) ;
278
+ dispatchEvent ( dragElement , touchstartEvent ) ;
279
+ fixture . detectChanges ( ) ;
280
+
281
+ dispatchTouchEvent ( document , 'touchmove' ) ;
282
+ fixture . detectChanges ( ) ;
283
+
284
+ expect ( touchstartEvent . preventDefault ) . not . toHaveBeenCalled ( ) ;
285
+ } ) ) ;
247
286
} ) ;
248
287
249
288
it ( 'should dispatch an event when the user has started dragging' , fakeAsync ( ( ) => {
0 commit comments