File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,16 @@ describe('CdkDrag', () => {
66
66
expect ( dragElement . style . transform ) . toBe ( 'translate3d(50px, 100px, 0px)' ) ;
67
67
} ) ) ;
68
68
69
+ it ( 'should drag an SVG element freely to a particular position' , fakeAsync ( ( ) => {
70
+ const fixture = createComponent ( StandaloneDraggableSvg ) ;
71
+ fixture . detectChanges ( ) ;
72
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
73
+
74
+ expect ( dragElement . getAttribute ( 'transform' ) ) . toBeFalsy ( ) ;
75
+ dragElementViaMouse ( fixture , dragElement , 50 , 100 ) ;
76
+ expect ( dragElement . getAttribute ( 'transform' ) ) . toBe ( 'translate(50 100)' ) ;
77
+ } ) ) ;
78
+
69
79
it ( 'should drag an element freely to a particular position when the page is scrolled' ,
70
80
fakeAsync ( ( ) => {
71
81
const fixture = createComponent ( StandaloneDraggable ) ;
@@ -2229,6 +2239,19 @@ class StandaloneDraggable {
2229
2239
endedSpy = jasmine . createSpy ( 'ended spy' ) ;
2230
2240
}
2231
2241
2242
+ @Component ( {
2243
+ template : `
2244
+ <svg><g
2245
+ cdkDrag
2246
+ #dragElement>
2247
+ <circle fill="red" r="50" cx="50" cy="50"/>
2248
+ </g></svg>
2249
+ `
2250
+ } )
2251
+ class StandaloneDraggableSvg {
2252
+ @ViewChild ( 'dragElement' ) dragElement : ElementRef < SVGElement > ;
2253
+ }
2254
+
2232
2255
@Component ( {
2233
2256
template : `
2234
2257
<div #dragElement cdkDrag
Original file line number Diff line number Diff line change @@ -491,6 +491,12 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
491
491
// Preserve the previous `transform` value, if there was one.
492
492
this . _rootElement . style . transform = this . _initialTransform ?
493
493
this . _initialTransform + ' ' + transform : transform ;
494
+
495
+ // Apply transform as attribute if dragging and svg element to work for IE
496
+ if ( typeof SVGElement !== 'undefined' && this . _rootElement instanceof SVGElement ) {
497
+ const appliedTransform = `translate(${ activeTransform . x } ${ activeTransform . y } )` ;
498
+ this . _rootElement . setAttribute ( 'transform' , appliedTransform ) ;
499
+ }
494
500
}
495
501
496
502
// Since this event gets fired for every pixel while dragging, we only
You can’t perform that action at this time.
0 commit comments