@@ -407,6 +407,51 @@ describe('CdkDrag', () => {
407
407
} ) ) ;
408
408
} ) ;
409
409
410
+ describe ( 'mouse dragging when initial transform is none' , ( ) => {
411
+ it ( 'should drag an element freely to a particular position' , fakeAsync ( ( ) => {
412
+ const fixture = createComponent ( StandaloneDraggableWithInitialTransformNone ) ;
413
+ fixture . detectChanges ( ) ;
414
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
415
+
416
+ expect ( dragElement . style . transform ) . toBe ( 'none' ) ;
417
+ dragElementViaMouse ( fixture , dragElement , 50 , 100 ) ;
418
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(50px, 100px, 0px)' ) ;
419
+ } ) ) ;
420
+
421
+ it ( 'should drag an SVG element freely to a particular position' , fakeAsync ( ( ) => {
422
+ const fixture = createComponent ( StandaloneDraggableSvgWithInitialTransformNone ) ;
423
+ fixture . detectChanges ( ) ;
424
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
425
+
426
+ expect ( dragElement . style . transform ) . toBe ( 'none' ) ;
427
+ dragElementViaMouse ( fixture , dragElement , 50 , 100 ) ;
428
+ expect ( dragElement . getAttribute ( 'transform' ) ) . toBe ( 'translate(50 100)' ) ;
429
+ } ) ) ;
430
+
431
+ it ( 'should drag an SVG element freely to a particular position in SVG viewBox coordinates' ,
432
+ fakeAsync ( ( ) => {
433
+ const fixture = createComponent ( StandaloneDraggableSvgWithViewBoxInitialTranformNone ) ;
434
+ fixture . detectChanges ( ) ;
435
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
436
+
437
+ expect ( dragElement . style . transform ) . toBe ( 'none' ) ;
438
+ dragElementViaMouse ( fixture , dragElement , 50 , 100 ) ;
439
+ expect ( dragElement . getAttribute ( 'transform' ) ) . toBe ( 'translate(100 200)' ) ;
440
+ } ) ) ;
441
+ } ) ;
442
+
443
+ describe ( 'touch dragging when initial transform is none' , ( ) => {
444
+ it ( 'should drag an element freely to a particular position' , fakeAsync ( ( ) => {
445
+ const fixture = createComponent ( StandaloneDraggableWithInitialTransformNone ) ;
446
+ fixture . detectChanges ( ) ;
447
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
448
+
449
+ expect ( dragElement . style . transform ) . toBe ( 'none' ) ;
450
+ dragElementViaTouch ( fixture , dragElement , 50 , 100 ) ;
451
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(50px, 100px, 0px)' ) ;
452
+ } ) ) ;
453
+ } ) ;
454
+
410
455
it ( 'should dispatch an event when the user has started dragging' , fakeAsync ( ( ) => {
411
456
const fixture = createComponent ( StandaloneDraggable ) ;
412
457
fixture . detectChanges ( ) ;
@@ -5936,6 +5981,21 @@ class StandaloneDraggable {
5936
5981
freeDragPosition ?: { x : number , y : number } ;
5937
5982
}
5938
5983
5984
+ @Component ( {
5985
+ template : `
5986
+ <div class="wrapper" style="width: 200px; height: 200px; background: green;">
5987
+ <div
5988
+ cdkDrag
5989
+ #dragElement
5990
+ style="transform: none; width: 100px; height: 100px; background: red;"></div>
5991
+ </div>
5992
+ `
5993
+ } )
5994
+ class StandaloneDraggableWithInitialTransformNone {
5995
+ @ViewChild ( 'dragElement' ) dragElement : ElementRef < HTMLElement > ;
5996
+ @ViewChild ( CdkDrag ) dragInstance : CdkDrag ;
5997
+ }
5998
+
5939
5999
@Component ( {
5940
6000
changeDetection : ChangeDetectionStrategy . OnPush ,
5941
6001
template : `
@@ -5960,6 +6020,34 @@ class StandaloneDraggableSvg {
5960
6020
@ViewChild ( 'dragElement' ) dragElement : ElementRef < SVGElement > ;
5961
6021
}
5962
6022
6023
+ @Component ( {
6024
+ template : `
6025
+ <svg><g
6026
+ cdkDrag
6027
+ style="transform: none"
6028
+ #dragElement>
6029
+ <circle fill="red" r="50" cx="50" cy="50"/>
6030
+ </g></svg>
6031
+ `
6032
+ } )
6033
+ class StandaloneDraggableSvgWithInitialTransformNone {
6034
+ @ViewChild ( 'dragElement' ) dragElement : ElementRef < SVGElement > ;
6035
+ }
6036
+
6037
+ @Component ( {
6038
+ template : `
6039
+ <svg width="400px" height="400px" viewBox="0 0 800 800"><g
6040
+ cdkDrag
6041
+ style="transform: none"
6042
+ #dragElement>
6043
+ <circle fill="red" r="50" cx="50" cy="50"/>
6044
+ </g></svg>
6045
+ `
6046
+ } )
6047
+ class StandaloneDraggableSvgWithViewBoxInitialTranformNone {
6048
+ @ViewChild ( 'dragElement' ) dragElement : ElementRef < SVGElement > ;
6049
+ }
6050
+
5963
6051
@Component ( {
5964
6052
template : `
5965
6053
<svg width="400px" height="400px" viewBox="0 0 800 800"><g
0 commit comments