Skip to content

Commit 1d83b74

Browse files
committed
Support Polymer 2.x shared styles
Add support for `:host, html` selectors in custom styles
1 parent 8ce0260 commit 1d83b74

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/lib/style-transformer.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@
292292

293293
normalizeRootSelector: function(rule) {
294294
rule.selector = rule.selector.replace(ROOT, 'html');
295+
// handle 2.x rules like `:host, html {}`
296+
var parts = rule.selector.split(COMPLEX_SELECTOR_SEP);
297+
parts = parts.filter(function(part) {
298+
return part.trim() !== HOST;
299+
});
300+
rule.selector = parts.join(COMPLEX_SELECTOR_SEP);
295301
},
296302

297303
_transformDocumentSelector: function(selector) {

test/unit/custom-style.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@
141141
--html-foo: 10px dotted green;
142142
}
143143
</style>
144+
<style is="custom-style">
145+
:host, html {
146+
--polymer-2-root: 10px solid rgb(123, 123, 123);
147+
}
148+
</style>
144149
</head>
145150
<body>
146151
<div class="italic">italic</div>
@@ -162,6 +167,8 @@
162167

163168
<parent-variable-with-var></parent-variable-with-var>
164169

170+
<polymer-2-root></polymer-2-root>
171+
165172
<br><br>
166173
<div id="after"></div>
167174

@@ -314,6 +321,16 @@
314321
</template>
315322
</dom-module>
316323

324+
<dom-module id="polymer-2-root">
325+
<template>
326+
<style>
327+
:host {
328+
border: var(--polymer-2-root);
329+
}
330+
</style>
331+
</template>
332+
</dom-module>
333+
317334
<script>
318335
HTMLImports.whenReady(function() {
319336
Polymer({
@@ -338,6 +355,9 @@
338355
Polymer({
339356
is: 'x-top-selectors'
340357
});
358+
Polymer({
359+
is: 'polymer-2-root'
360+
})
341361
})
342362
</script>
343363

@@ -386,6 +406,11 @@
386406
assertComputed(xFoo.$.bar3.$.baz, '5px');
387407
});
388408

409+
test('polymer 2 shared styles applied', function() {
410+
var polymer2 = document.querySelector('polymer-2-root');
411+
assertComputed(polymer2, '10px');
412+
})
413+
389414
test('custom properties registered as defaults', function() {
390415
var propsToCheck = ['--italic'];
391416
if (Polymer.Settings.useNativeCSSProperties || stylesBuilt) {

0 commit comments

Comments
 (0)