Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix class$ bindings for ShadyDOM.noPatch mode #5534

Merged
merged 2 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/mixins/properties-changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,12 @@ export const PropertiesChanged = dedupingMixin(
*/
_valueToNodeAttribute(node, value, attribute) {
const str = this._serializeValue(value);
if (attribute === 'class' || attribute === 'name' || attribute === 'slot') {
node = /** @type {?Element} */(wrap(node));
}
if (str === undefined) {
node.removeAttribute(attribute);
} else {
if (attribute === 'class' || attribute === 'name' || attribute === 'slot') {
node = /** @type {?Element} */(wrap(node));
}
node.setAttribute(attribute, str);
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,31 @@
</script>
</dom-module>

<script type="module">
import { PolymerElement, html } from '../../polymer-element.js';
class ClassBindingUndefined extends PolymerElement {
static get is() { return 'class-binding-undefined'; }
static get properties() {
return {
data: {
type: Object
}
};
}
static get template() {
return html`
<style>
div {
border: 10px solid black;
}
</style>
<div id="div" class$="[[data.class]]">Foo</div>
`;
}
}
customElements.define(ClassBindingUndefined.is, ClassBindingUndefined);
</script>

<script type="module">
import { dom } from '../../lib/legacy/polymer.dom.js';
import { flush } from '../../lib/utils/flush.js';
Expand Down Expand Up @@ -1015,6 +1040,13 @@
assert.isTrue(el.classList.contains('e'));
});

test('scoping classes are preserved when a class$ binding resolves to undefined', function() {
const e = document.createElement('class-binding-undefined');
document.body.appendChild(e);
const el = e.$.div;
assertComputed(el, '10px');
});

});

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