Ensure initial static classes are preserved when a class$ binding is present.

This ensures ShadyCSS scoping classes are not removed when a class binding's initial literal value is set.
This commit is contained in:
Steven Orvell
2018-11-09 18:04:58 -08:00
parent 5b34ce9d83
commit 83c0e9d143
2 changed files with 29 additions and 0 deletions
+5
View File
@@ -2551,6 +2551,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// 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
+24
View File
@@ -160,6 +160,19 @@ HTMLImports.whenReady(function() {
</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">
@@ -1041,6 +1054,17 @@ HTMLImports.whenReady(function() {
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() {