Skip to content

Commit

Permalink
Fixes #1277
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Mar 11, 2015
1 parent 2138075 commit 860ce4c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/style-util.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
style.textContent = cssText;
target = target || document.head;
if (lowPriority) {
target.insertBefore(style, target.firstChild);
} else {
var n$ = target.querySelectorAll('style[scope]');
var ref = n$.length ? n$[n$.length-1].nextSibling : target.firstChild;
target.insertBefore(style, ref);
} else {
target.appendChild(style);
}
return style;
Expand Down
21 changes: 21 additions & 0 deletions test/unit/scoped-styling-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
});
</script>

<dom-module id="x-child2">
<style>
:host(.wide) #target{
border: none;
}
</style>
<template>
<div id="target">x-child2</div>
</template>
</dom-module>
<script>
Polymer({
is: 'x-child2'
});
</script>

<dom-module id="x-styled">
<style>
:host {
Expand Down Expand Up @@ -54,6 +70,10 @@
#priority {
border: 9px solid orange;
}

x-child2.wide::shadow #target {
border: 12px solid brown;
}
</style>
<template>
<div id="simple">simple</div>
Expand All @@ -65,6 +85,7 @@
</div>
<x-child id="child"></x-child>
<div id="priority">priority</div>
<x-child2 class="wide" id="child2"></x-child2>
</template>
</dom-module>
<script>
Expand Down
10 changes: 10 additions & 0 deletions test/unit/scoped-styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@
assertComputed(button, '10px');
assertComputed(specialButton, '11px');
});

test('styles shimmed in registration order', function() {
var s$ = document.head.querySelectorAll('style[scope]');
var expected = ['x-child2', 'x-styled', 'x-button'];
var actual = [];
for (var i=0; i<s$.length; i++) {
actual.push(s$[i].getAttribute('scope'));
}
assert.deepEqual(actual, expected);
});

});

Expand Down

0 comments on commit 860ce4c

Please sign in to comment.