Skip to content

Commit

Permalink
Merge pull request #1148 from Polymer/shadow-root-options
Browse files Browse the repository at this point in the history
Adds `shadowRootOptions` feature
  • Loading branch information
Steve Orvell committed Feb 4, 2021
2 parents d97341d + fa79717 commit eeadf21
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added
* Adds a `static shadowRootOptions` property for specifying shadow root options. This is a slightly simpler alternative to implementing a custom `createRenderRoot` method [#1147](https://github.com/Polymer/lit-element/issues/1147).

### Fixed
* Fixes an issue with `queryAssignedNodes` when applying a selector on a slot that included text nodes on older browsers not supporting Element.matches [#1088](https://github.com/Polymer/lit-element/issues/1088).

Expand Down
5 changes: 4 additions & 1 deletion src/lit-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export class LitElement extends UpdatingElement {
*/
static styles?: CSSResultOrNative|CSSResultArray;

static shadowRootOptions: ShadowRootInit = { mode: "open" };

private static _styles: Array<CSSResultOrNative|CSSResult>|undefined;

/**
Expand Down Expand Up @@ -236,7 +238,8 @@ export class LitElement extends UpdatingElement {
* @returns {Element|DocumentFragment} Returns a node into which to render.
*/
protected createRenderRoot(): Element|ShadowRoot {
return this.attachShadow({mode: 'open'});
return this.attachShadow(
(this.constructor as typeof LitElement).shadowRootOptions);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/test/lit-element_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,18 @@ suite('LitElement', () => {
a,
'testDom should be a child of the component');
});

(window.ShadyDOM && window.ShadyDOM.inUse ? test.skip : test)(
"can customize shadowRootOptions",
async () => {
class A extends LitElement {
static shadowRootOptions: ShadowRootInit = { mode: "closed" };
}
customElements.define(generateElementName(), A);
const a = new A();
container.appendChild(a);
await a.updateComplete;
assert.equal(a.shadowRoot, undefined);
}
);
});

0 comments on commit eeadf21

Please sign in to comment.