Skip to content

Commit

Permalink
Always update style properties when calling getComputedStyleValue
Browse files Browse the repository at this point in the history
Fixes #4125
  • Loading branch information
dfreedm committed Nov 3, 2016
1 parent f24dea1 commit fb8575c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/standard/x-styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
* @return {String} the computed value
*/
getComputedStyleValue: function(property) {
// refresh the style properties for this node
this._updateStyleProperties();
return !nativeVariables && this._styleProperties &&
this._styleProperties[property] ||
getComputedStyle(this).getPropertyValue(property);
Expand Down Expand Up @@ -212,12 +214,14 @@
},

_computeOwnStyleProperties: function() {
var props = {};
for (var i=0, n; i < this._ownStylePropertyNames.length; i++) {
n = this._ownStylePropertyNames[i];
props[n] = this._styleProperties[n];
if (this._ownStylePropertyNames) {
var props = {};
for (var i=0, n; i < this._ownStylePropertyNames.length; i++) {
n = this._ownStylePropertyNames[i];
props[n] = this._styleProperties[n];
}
this._ownStyleProperties = props;
}
this._ownStyleProperties = props;
},

_scopeCount: 0,
Expand Down
32 changes: 32 additions & 0 deletions test/unit/styling-cross-scope-var.html
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,30 @@
</script>
</dom-module>

<dom-module id="prop-inner">
<script>
HTMLImports.whenReady(function() {
Polymer({is: 'prop-inner'});
});
</script>
</dom-module>

<dom-module id="prop-outer">
<template>
<style>
:host {
--foo: orange;
}
</style>
<prop-inner id="inner"></prop-inner>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({is: 'prop-outer'});
});
</script>
</dom-module>

<script>
suite('scoped-styling-var', function() {

Expand Down Expand Up @@ -1307,6 +1331,14 @@
assertComputed(e.$.root, '2px');
assertComputed(e.$.host, '10px');
});

test('elements in the dom should be able to query for inherited variables', function() {
var e = document.createElement('prop-outer');
document.body.appendChild(e);
CustomElements.takeRecords();
assert.equal(e.getComputedStyleValue('--foo'), 'orange');
assert.equal(e.$.inner.getComputedStyleValue('--foo'), 'orange');
})
});

</script>
Expand Down

0 comments on commit fb8575c

Please sign in to comment.