@@ -18,6 +18,7 @@ import {
1818 dispatchEvent ,
1919 dispatchMouseEvent ,
2020 dispatchTouchEvent ,
21+ createTouchEvent ,
2122} from '@angular/cdk/testing' ;
2223import { Directionality } from '@angular/cdk/bidi' ;
2324import { CdkDrag , CDK_DRAG_CONFIG , CdkDragConfig } from './drag' ;
@@ -169,6 +170,25 @@ describe('CdkDrag', () => {
169170 expect ( dragElement . style . transform ) . toBe ( 'translateY(-50%) translate3d(150px, 300px, 0px)' ) ;
170171 } ) ) ;
171172
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+
172192 } ) ;
173193
174194 describe ( 'touch dragging' , ( ) => {
@@ -244,6 +264,25 @@ describe('CdkDrag', () => {
244264 dispatchTouchEvent ( document , 'touchend' ) ;
245265 fixture . detectChanges ( ) ;
246266 } ) ) ;
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+ } ) ) ;
247286 } ) ;
248287
249288 it ( 'should dispatch an event when the user has started dragging' , fakeAsync ( ( ) => {
0 commit comments