Skip to content

Commit

Permalink
Merge pull request #5153 from Polymer/null-template-inheritance
Browse files Browse the repository at this point in the history
Returning null in template should nullify parent template
  • Loading branch information
TimvdLippe authored Mar 15, 2018
2 parents 5422bef + b2fb1cf commit 4629933
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@
} else {
template = template.cloneNode(true);
}
this.prototype._template = template;
}

this.prototype._template = template;
}

/**
Expand Down
37 changes: 36 additions & 1 deletion test/unit/inheritance.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@
</script>
</dom-module>

<dom-module id="parent-element-template-overriding">
<script>
HTMLImports.whenReady(function() {
class ParentElementWithTemplate extends Polymer.Element {
static get template() {
return Polymer.html`This template should not exist`;
}
}
class ChildWithNoTemplate extends ParentElementWithTemplate {
static get template() {
return null;
}
}
customElements.define('child-with-no-template', ChildWithNoTemplate);
});
</script>
</dom-module>

<test-fixture id="basic">
<template>
<base-el></base-el>
Expand Down Expand Up @@ -237,6 +255,23 @@
assert.equal(child.handleCustomEvent.callCount, 1);
});
});

suite('child overriding a template', function() {
let el;

setup(function() {
el = document.createElement('child-with-no-template');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('returning null nullifies the parent template', function() {
assert.equal(el.shadowRoot, null);
});
});
</script>
</body>
</html>
</html>

0 comments on commit 4629933

Please sign in to comment.