Skip to content

Commit

Permalink
updateNativeStyles should only remove styles set by updateNativeStyles
Browse files Browse the repository at this point in the history
Fixes #3800
  • Loading branch information
dfreedm committed Jul 25, 2016
1 parent 43955ea commit 831be4f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/style-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,23 @@
* support element.customStyle / element.updateStyles)
*/
updateNativeStyleProperties: function(element, properties) {
// remove existing properties
for (var i=0; i < element.style.length; i++) {
element.style.removeProperty(element.style[i]);
var oldPropertyNames = element.__customStyleProperties;
if (oldPropertyNames) {
// remove previous properties
for (var i=0; i < oldPropertyNames.length; i++) {
element.style.removeProperty(oldPropertyNames[i]);
}
}
var propertyNames = [];
// apply properties
for (var p in properties) {
// NOTE: for bc with shim, don't apply null values.
if (properties[p] !== null) {
element.style.setProperty(p, properties[p]);
propertyNames.push(p);
}
}
element.__customStyleProperties = propertyNames;
},

rx: styleUtil.rx,
Expand Down
27 changes: 27 additions & 0 deletions test/unit/styling-cross-scope-var.html
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,33 @@
CustomElements.takeRecords();
assertComputed(e, 'rgb(102, 205, 170)', null, 'color');
});

test('updateStyles plays nicely with inline styling', function() {
if (!Polymer.Settings.useNativeCSSProperties) {
this.skip();
}
var e = document.createElement('x-dynamic');
document.body.appendChild(e);
CustomElements.takeRecords();
e.style.cssText = 'background-color: rgb(255, 0, 0);';
e.updateStyles();
assertComputed(e, 'rgb(255, 0, 0)', null, 'background-color');
});
test('updateStyles removes the correct number of style properties', function() {
if (!Polymer.Settings.useNativeCSSProperties) {
this.skip();
}
var e = document.createElement('x-dynamic');
document.body.appendChild(e);
CustomElements.takeRecords();
e.style.cssText = 'background-color: rgb(255, 0, 0);';
e.updateStyles({'--dynamic': '2px solid black'});
assertComputed(e, 'rgb(255, 0, 0)', null, 'background-color');
assertComputed(e, '2px');
e.updateStyles({'--dynamic': null});
assertComputed(e, 'rgb(255, 0, 0)', null, 'background-color');
assertComputed(e, '6px');
});
});

</script>
Expand Down

0 comments on commit 831be4f

Please sign in to comment.