Skip to content

Commit

Permalink
add optional isolate param
Browse files Browse the repository at this point in the history
  • Loading branch information
raynirola committed Apr 23, 2024
1 parent fc6a24f commit 711ac87
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/dom/createShadowRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface HTMLShadowDOMElement extends HTMLDivElement {
* @param options the optional options for the shadow root.
* @returns A Div that represents the shadow root with some additional methods added to it.
*/
export function createShadowDOM(id: string, options?: ShadowRootInit): HTMLShadowDOMElement {
export function createShadowDOM(id: string, options?: ShadowRootInit, isolate = false): HTMLShadowDOMElement {
const html = document.querySelector('html');
if (!html) {
throw new Error('Could not find html element');
Expand All @@ -47,5 +47,8 @@ export function createShadowDOM(id: string, options?: ShadowRootInit): HTMLShado
};

html.appendChild(div);

if(isolate) document.body.style.isolation = 'isolate';

return div as HTMLShadowDOMElement;
}

0 comments on commit 711ac87

Please sign in to comment.