Skip to content

Commit b58343a

Browse files
author
Steve Orvell
committed
Merge pull request Polymer#1797 from Polymer/fix-1752
Fix 1752
2 parents 622c731 + 1273227 commit b58343a

File tree

4 files changed

+130
-16
lines changed

4 files changed

+130
-16
lines changed

src/lib/style-defaults.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
this._styles._scopeStyleProperties = null;
3737
this._properties = styleProperties
3838
.scopePropertiesFromStyles(this._styles);
39+
styleProperties.reify(this._properties);
3940
}
4041
return this._properties;
4142
},

test/smoke/custom-reify.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
5+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8+
Code distributed by Google as part of the polymer project is also
9+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10+
-->
11+
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
12+
<link rel="import" href="../../polymer.html">
13+
14+
<body>
15+
<style is="custom-style">
16+
:root {
17+
--mood1: orange;
18+
--mood: var(--mood1);
19+
20+
/* --mood: yellow; */
21+
}
22+
23+
</style>
24+
25+
<style is="custom-style">
26+
.zonk {
27+
--mood1: red;
28+
}
29+
30+
.bar {
31+
--mood1: blue;
32+
}
33+
</style>
34+
35+
36+
37+
<x-test class="zonk"></x-test>
38+
39+
<x-test class="bar"></x-test>
40+
41+
<dom-module id="x-test">
42+
<style>
43+
.mood {
44+
/* background: var(--mood1, --mood); */
45+
background: var(--mood);
46+
}
47+
</style>
48+
<template>
49+
<div class="mood">Mood</div>
50+
</template>
51+
<script>
52+
addEventListener('HTMLImportsLoaded', function() {
53+
Polymer({
54+
is: 'x-test'
55+
});
56+
});
57+
</script>
58+
</dom-module>
59+
60+
61+
</body>
62+

test/unit/custom-style.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
}, 0);
183183
});
184184

185-
test('custom-styles apply normal and property values to elements', function() {
185+
test('custom-styles apply normal and property values to elements and cannot be late bound via inheritance', function() {
186186
var e = document.querySelector('x-foo').$.me;
187187
assertComputed(e, '1px');
188188
});

test/unit/styling-cross-scope-var.html

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,49 @@
156156
</script>
157157
</dom-module>
158158

159+
<dom-module id="x-late">
160+
<style>
161+
:host {
162+
border: var(--late);
163+
display: block;
164+
}
165+
</style>
166+
167+
<template>
168+
late
169+
</template>
170+
<script>
171+
HTMLImports.whenReady(function() {
172+
Polymer({is: 'x-late'});
173+
});
174+
</script>
175+
</dom-module>
176+
177+
<dom-module id="x-overrides3">
178+
<style>
179+
:host {
180+
border: 1px dashed gray;
181+
margin: 8px;
182+
padding: 8px;
183+
display: block;
184+
}
185+
186+
:root {
187+
--fillin: 16px;
188+
}
189+
</style>
190+
191+
<template>
192+
overrides:
193+
<x-late id="late"></x-late>
194+
</template>
195+
<script>
196+
HTMLImports.whenReady(function() {
197+
Polymer({is: 'x-overrides3'});
198+
});
199+
</script>
200+
</dom-module>
201+
159202
<dom-module id="x-has-if">
160203
<style>
161204
.iffy {
@@ -194,6 +237,7 @@
194237
--a: 10px;
195238
--b: 5px;
196239
--primary-color: rgb(128, 128, 128);
240+
--late: var(--fillin);
197241
}
198242

199243
#me {
@@ -230,11 +274,11 @@
230274
background-color: var(--default3);
231275
}
232276

233-
#overrides1, #overrides2, #overrides3 {
277+
#overrides1a, #overrides1b, #overrides2 {
234278
--rename: 8px solid navy;
235279
}
236280

237-
#overrides2, #overrides3 {
281+
#overrides1b, #overrides2 {
238282
--grand-child-scope-var: 9px solid orange;
239283
}
240284

@@ -261,9 +305,10 @@
261305
<div id="me">x-scope</div>
262306
<x-child-scope id="child"></x-child-scope>
263307
<x-child-scope id="child2"></x-child-scope>
264-
<x-overrides id="overrides1"></x-overrides>
265-
<x-overrides id="overrides2"></x-overrides>
266-
<x-overrides2 id="overrides3"></x-overrides2>
308+
<x-overrides id="overrides1a"></x-overrides>
309+
<x-overrides id="overrides1b"></x-overrides>
310+
<x-overrides2 id="overrides2"></x-overrides2>
311+
<x-overrides3 id="overrides3"></x-overrides3>
267312
<div id="default1">default</div>
268313
<div id="default2">var default</div>
269314
<div id="default3">tricky property rgb(...) default</div>
@@ -398,20 +443,26 @@
398443

399444
test('variable precedence and overrides', function() {
400445
// renamed property applied
401-
var o1 = styled.$.overrides1;
402-
assertStylePropertyValue(o1._styleProperties, '--rename', '8px');
403-
assertStylePropertyValue(o1._styleProperties, '--grand-child-scope-var', '8px');
404-
assertComputed(o1.$.gc1.$.me, '8px');
446+
var o1a = styled.$.overrides1a;
447+
assertStylePropertyValue(o1a._styleProperties, '--rename', '8px');
448+
assertStylePropertyValue(o1a._styleProperties, '--grand-child-scope-var', '8px');
449+
assertComputed(o1a.$.gc1.$.me, '8px');
405450
// :host property overridden by outer scope
451+
var o1b = styled.$.overrides1b;
452+
assertStylePropertyValue(o1b._styleProperties, '--rename', '8px');
453+
assertStylePropertyValue(o1b._styleProperties, '--grand-child-scope-var', '9px');
454+
assertComputed(o1b.$.gc1.$.me, '9px');
455+
// own scope property overrides outer scope
406456
var o2 = styled.$.overrides2;
407457
assertStylePropertyValue(o2._styleProperties, '--rename', '8px');
408-
assertStylePropertyValue(o2._styleProperties, '--grand-child-scope-var', '9px');
409-
assertComputed(o2.$.gc1.$.me, '9px');
410-
// own scope property overrides outer scope
458+
assertStylePropertyValue(o2._styleProperties, '--grand-child-scope-var', '8px');
459+
assertComputed(o2.$.gc1.$.me, '8px');
460+
461+
// late bound property does *not* resolve using inherited value
411462
var o3 = styled.$.overrides3;
412-
assertStylePropertyValue(o3._styleProperties, '--rename', '8px');
413-
assertStylePropertyValue(o3._styleProperties, '--grand-child-scope-var', '8px');
414-
assertComputed(o3.$.gc1.$.me, '8px');
463+
assert.equal(o3._styleProperties['--late'], '', 'property should not be late bound');
464+
assertStylePropertyValue(o3._styleProperties, '--fillin', '16px');
465+
assertComputed(o3.$.late, '0px');
415466

416467
});
417468

0 commit comments

Comments
 (0)