New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(drag-drop): add support for dragging svg elements in IE11 #14215
Conversation
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 attribute - IE11's getComputedStyle returns a matrix3d(), but doesn't allow that to be passed via setAttribute Closes angular#14214
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
Signed CLA with my other email as well... |
CLAs look good, thanks! |
src/cdk/drag-drop/drag.ts
Outdated
|
||
// Apply transform as attribute if dragging and svg element to work for IE | ||
if (this._rootElement instanceof SVGElement) { | ||
let appliedTransform = getComputedStyle(this._rootElement).getPropertyValue('transform'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent here was to only preserve the inline style transform
since we replace the entire style.transform
and getting the attribute value is fairly cheap. Doing a getComputedStyle
introduces a potential performance issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I changed it to use the activeTransform
values. Is that appropriate?
src/cdk/drag-drop/drag.ts
Outdated
if (this._rootElement instanceof SVGElement) { | ||
let appliedTransform = getComputedStyle(this._rootElement).getPropertyValue('transform'); | ||
// Check if the value is a matrix3d(), and convert to matrix() for IE compatibility | ||
const match = appliedTransform.match(/^matrix3d\((.+)\)$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think using a matrix here is necessary. From what I can tell, IE supports stacking the SVG transforms similarly to the CSS ones. E.g. note how the blue square has translate(50) translate(-25)
here: https://s.codepen.io/crisbeto/debug/qQpqrQ/ZoABaKZbgybr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, translate()
works, and greatly simplifies things. Changed.
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 attribute. Closes angular#14214
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 attribute. Closes angular#14214
src/cdk/drag-drop/drag.spec.ts
Outdated
<svg><g | ||
cdkDrag | ||
(cdkDragStarted)="startedSpy($event)" | ||
(cdkDragEnded)="endedSpy($event)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start and end events can be removed since they aren't being used in any of the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/cdk/drag-drop/drag.ts
Outdated
@@ -491,6 +491,12 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy { | |||
// Preserve the previous `transform` value, if there was one. | |||
this._rootElement.style.transform = this._initialTransform ? | |||
this._initialTransform + ' ' + transform : transform; | |||
|
|||
// Apply transform as attribute if dragging and svg element to work for IE | |||
if (this._rootElement instanceof SVGElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's unlikely, this has the potential of throwing an error during server-side rendering. Changing it to typeof SVGElement !== 'undefined' && this._rootElement instanceof SVGElement
should avoid the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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 attribute. Closes angular#14214
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
…r#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 angular#14214
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Added check for when _rootElement is an SVGElement and set the transform attribute as well.
Closes #14214