-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngStyle): skip setting empty value when new style has the property #16709
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
1 similar comment
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
1 similar comment
CLAs look good, thanks! |
Previously, all the properties in oldStyles are set to empty value once. Using AngularJS with jQuery 3.3.1, this disables the CSS transition as reported in jquery/jquery#4185.
src/ng/directive/ngStyle.js
Outdated
forEach(oldStyles, function(val, style) { element.css(style, '');}); | ||
forEach(oldStyles, function(val, style) { | ||
if (!(newStyles && newStyles.hasOwnProperty(style))) { | ||
element.css(style, ''); |
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.
Incorrect indentation.
src/ng/directive/ngStyle.js
Outdated
@@ -54,7 +54,11 @@ | |||
var ngStyleDirective = ngDirective(function(scope, element, attr) { | |||
scope.$watchCollection(attr.ngStyle, function ngStyleWatchAction(newStyles, oldStyles) { | |||
if (oldStyles && (newStyles !== oldStyles)) { | |||
forEach(oldStyles, function(val, style) { element.css(style, '');}); | |||
forEach(oldStyles, function(val, style) { | |||
if (!(newStyles && newStyles.hasOwnProperty(style))) { |
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.
What if newStyles
does have the property, but the value is undefined
or null
?
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.
Right, in that case the style should be cleared. Fixed in 5d74f0f.
Looks reasonable. I'd still wait for a response from the jQuery team on whether this change was intentional or not. |
src/ng/directive/ngStyle.js
Outdated
forEach(oldStyles, function(val, style) { element.css(style, '');}); | ||
forEach(oldStyles, function(val, style) { | ||
if (!(newStyles && newStyles[style])) { | ||
element.css(style, ''); |
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.
Would it be possible to do newStyles[style] = ''
instead (maybe also needing a newStyles
null check + assign). This way we will only make a single element.css(newStyles)
call at the end instead of multiple .css
calls.
Also should this be an undefined
/null
check instead of just falsey check? What if newStyles[style]
is 0
?
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.
For sure. Fixed in 95d2458.
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 👍
It would be nice to have a tests that verifies that falsy style values (e.g. 0
) are still updated correctly.
Landed, thanks! |
Thank you! |
Previously, all the properties in oldStyles are set to empty value once. Using AngularJS with jQuery 3.3.1, this disables the CSS transition as reported in jquery/jquery#4185. Closes #16709
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.
What is the current behavior? (You can also link to an open issue here)
Using ng-style with CSS transition with jQuery 3.3.1 (currently the latest tag), the animation is disabled in certain circumstances.
https://jsfiddle.net/qz5a46yc/1/
Without jQuery (using jqLite.css) or using jQuery 3.2.1, the div animates. I reported to the jQuery dev on this behavior difference: jquery/jquery#4185. I think this is a bug in jQuery.
This pull request suggests a workaround on the disabled animation issue. I'm not sure how the report to the jQuery will be handled, but we can fix the behavior with reasonable changes in AngularJS. Skipping the common properties with newStyles will fix the animation issue with jQuery 3.3.1, which can be confirmed by https://jsfiddle.net/g3st70fh/1/. I think the diff is reasonable and also improves the performance because the properties in oldStyles and newStyles are same in most cases.
What is the new behavior (if this is a feature change)?
I believe there's no changes except for fixing the animation issue.
Does this PR introduce a breaking change?
No, I believe.
Please check if the PR fulfills these requirements
Other information: