Skip to content

Commit 81db16c

Browse files
evanfuturejelbourn
authored andcommittedDec 3, 2018
fix(drag-drop): add support for dragging svg elements in IE11 (#14215)
Added check for when _rootElement is an SVGElement and set the transform attribute as well. IE11 does not acknowledge the style.transform property, but does allow the `transform` attribute Closes #14214
1 parent ad75cad commit 81db16c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎src/cdk/drag-drop/drag.spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ describe('CdkDrag', () => {
6666
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');
6767
}));
6868

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+
6979
it('should drag an element freely to a particular position when the page is scrolled',
7080
fakeAsync(() => {
7181
const fixture = createComponent(StandaloneDraggable);
@@ -2229,6 +2239,19 @@ class StandaloneDraggable {
22292239
endedSpy = jasmine.createSpy('ended spy');
22302240
}
22312241

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+
22322255
@Component({
22332256
template: `
22342257
<div #dragElement cdkDrag

‎src/cdk/drag-drop/drag.ts

+6
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
491491
// Preserve the previous `transform` value, if there was one.
492492
this._rootElement.style.transform = this._initialTransform ?
493493
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+
}
494500
}
495501

496502
// Since this event gets fired for every pixel while dragging, we only

0 commit comments

Comments
 (0)
Please sign in to comment.