Skip to content

Commit

Permalink
Make shadow roots always open (resolves #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeckem committed Dec 1, 2023
1 parent 6f954e3 commit ce9e060
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/bright-donkeys-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@open-pioneer/runtime": major
---

Remove support for closed shadow roots.
Shadow roots used by trails applications are now always `"open"`.
See #19.
7 changes: 3 additions & 4 deletions src/packages/runtime/CustomElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,16 @@ describe("simple rendering", function () {
});
});

it("explicitly setting the shadow dom mode hides the shadow root", async () => {
it("uses mode 'open' for the internal shadow root", async () => {
function TestComponent() {
return createElement("span", undefined, "Hello World");
}

const elem = createCustomElement({
component: TestComponent,
openShadowRoot: false
component: TestComponent
});
const { node } = await renderComponent(elem);
expect(node.shadowRoot).toBeNull();
expect(node.shadowRoot).toBeTruthy();
});

it("allows customization of package properties", async () => {
Expand Down
9 changes: 1 addition & 8 deletions src/packages/runtime/CustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ export interface CustomElementOptions {
*/
resolveConfig?(ctx: ConfigContext): Promise<ApplicationConfig | undefined>;

/**
* Whether the shadow root element is accessible from the outside.
* Defaults to `false` in production mode and `true` during development to make testing easier.
*/
openShadowRoot?: boolean;

/**
* Chakra theming object.
*/
Expand Down Expand Up @@ -161,9 +155,8 @@ export function createCustomElement(options: CustomElementOptions): ApplicationE
constructor() {
super();

const mode = options.openShadowRoot ?? import.meta.env.DEV ? "open" : "closed";
this.#shadowRoot = this.attachShadow({
mode: mode
mode: "open"
});

if (import.meta.env.DEV) {
Expand Down

0 comments on commit ce9e060

Please sign in to comment.