Skip to content

Commit

Permalink
Include shadowroot in fallback clone #13
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 12, 2022
1 parent 115c459 commit c27f6a8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions is-land.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class Island extends HTMLElement {
cloned.setAttribute(attr, node.getAttribute(attr));
}

// declarative shadow dom
// cheers to https://gist.github.com/developit/45c85e9be01e8c3f1a0ec073d600d01e
let shadowroot = node.shadowRoot;
if(shadowroot) {
cloned.attachShadow({ mode: shadowroot.mode }).append(...[].map.call(shadowroot.childNodes, c => c.cloneNode(true)));
}

let children = Array.from(node.childNodes);
for(let child of children) {
cloned.append(child); // Keep the *same* child nodes, clicking on a details->summary child should keep the state of that child
Expand Down

0 comments on commit c27f6a8

Please sign in to comment.