Skip to content

Commit

Permalink
Ensure initial static classes are preserved when a class$ binding is …
Browse files Browse the repository at this point in the history
…present.

This ensures ShadyCSS scoping classes are not removed when a class binding's initial literal value is set.
  • Loading branch information
Steven Orvell committed Nov 10, 2018
1 parent 5b34ce9 commit 83c0e9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,11 @@
// Initialize attribute bindings with any literal parts
let literal = literalFromParts(parts);
if (literal && kind == 'attribute') {
// Ensure a ShadyCSS template scoped style is not removed
// when a class$ binding's initial literal value is set.
if (name == 'class' && node.hasAttribute('class')) {
literal += ' ' + node.getAttribute(name);
}
node.setAttribute(name, literal);
}
// Clear attribute before removing, since IE won't allow removing
Expand Down
24 changes: 24 additions & 0 deletions test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@
</script>
</dom-module>

<dom-module id="x-class-literal">
<template>
<div id="scope" class$="a [[b]] c" class="d e">Trivial</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-class-literal'
});
});
</script>
</dom-module>



<dom-module id="x-styled">
Expand Down Expand Up @@ -1041,6 +1054,17 @@
assertComputed(e, '2px');
});

test('initial literal values in class are preserved when a class$ binding is present', function() {
var e = document.createElement('x-class-literal');
document.body.appendChild(e);
var el = e.$.scope;
assert.equal(el.classList.length, 4);
assert.isTrue(el.classList.contains('a'));
assert.isTrue(el.classList.contains('c'));
assert.isTrue(el.classList.contains('d'));
assert.isTrue(el.classList.contains('e'));
});

});

suite('double including style sheets', function() {
Expand Down

0 comments on commit 83c0e9d

Please sign in to comment.