How to insert <style>...</style> into <head> of Shadow Root #1600
Answered
by
mengxi-ream
mengxi-ream
asked this question in
Q&A
-
What I want to do is: document.head.querySelectorAll("style").forEach((styleEl) => {
if (styleEl.textContent?.includes("[data-sonner-toaster]")) {
// shadow.append(styleEl);
console.log("styleEl.textContent", styleEl);
}
}); background info: https://sonner.emilkowal.ski/other#shadow-dom-support Can I ask how to do this in WXT, I want to insert to the of Shadow Root |
Beta Was this translation helpful? Give feedback.
Answered by
mengxi-ream
Apr 22, 2025
Replies: 1 comment
-
solve by: onMount: (container, shadow) => {
const wrapper = document.createElement("div");
container.appendChild(wrapper);
const root = ReactDOM.createRoot(wrapper);
document.head.querySelectorAll("style").forEach((styleEl) => {
if (styleEl.textContent?.includes("[data-sonner-toaster]")) {
const shadowHead = shadow.querySelector("head");
if (shadowHead) {
shadowHead.append(styleEl);
} else {
shadow.append(styleEl);
}
console.log("styleEl.textContent", styleEl);
}
});
...
},
``` |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mengxi-ream
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solve by: