Skip to content
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

Merged
merged 4 commits into from Nov 27, 2018

Conversation

evanfuture
Copy link
Contributor

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 #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
- IE11's getComputedStyle returns a matrix3d(), but doesn't allow that to be passed via setAttribute

Closes angular#14214
@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot googlebot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label Nov 20, 2018
@evanfuture
Copy link
Contributor Author

Signed CLA with my other email as well...

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Nov 20, 2018

// 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');
Copy link
Member

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.

Copy link
Contributor Author

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?

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\((.+)\)$/);
Copy link
Member

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

Copy link
Contributor Author

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.

Evan Payne added 2 commits November 21, 2018 05:46
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
<svg><g
cdkDrag
(cdkDragStarted)="startedSpy($event)"
(cdkDragEnded)="endedSpy($event)"
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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) {
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 21, 2018
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn merged commit 889dca8 into angular:master Nov 27, 2018
jelbourn pushed a commit that referenced this pull request Dec 3, 2018
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
josephperrott pushed a commit to josephperrott/components that referenced this pull request Jan 14, 2019
…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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svg elements can't be dragged in IE11
4 participants