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 inherit from constructor chain #468

Closed
Closed
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
4 changes: 2 additions & 2 deletions src/lit-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class LitElement extends UpdatingElement {
private static get _uniqueStyles(): CSSResult[] {
if (!this.hasOwnProperty(JSCompiler_renameProperty('_styles', this))) {
// Inherit styles from superclass if none have been set.
if (!this.hasOwnProperty(JSCompiler_renameProperty('styles', this))) {
this._styles = this._styles !== undefined ? this._styles : [];
if (!this[JSCompiler_renameProperty('styles', this)]) {
this._styles = [];
} else {
// Take care not to call `this.styles` multiple times since this generates
// new CSSResults each time.
Expand Down
24 changes: 24 additions & 0 deletions src/test/lit-element_styling_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,30 @@ suite('Static get styles', () => {
assert.equal(getComputedStyleValue(div!, 'border-top-width').trim(),
'4px');
});

test('inherits `styles` from constructor chain', async () => {
const base = generateElementName();
customElements.define(base, class extends LitElement {
static get styles() { return css`div {
border: 2px solid blue;
}`;
}

render() {
return htmlWithStyles`
<div>Testing1</div>`;
}
});

const sub = generateElementName();
customElements.define(sub, class extends customElements.get(base) {});

const el = document.createElement(sub);
container.appendChild(el);
await (el as LitElement).updateComplete;
const div = el.shadowRoot!.querySelector('div');
assert.equal(getComputedStyleValue(div!, 'border-top-width').trim(), '2px');
});
});

suite('ShadyDOM', () => {
Expand Down