Skip to content

Commit

Permalink
Prevent CSS conflicts breaking UI (#65)
Browse files Browse the repository at this point in the history
Renders UI to ShadowDOM elements, preventing external CSS rules
interferring with desired import-map UI.
  • Loading branch information
ralphsaunders authored Mar 22, 2022
1 parent d75295d commit 62384b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ui/custom-elements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./import-map-overrides.css";
import styles from "./import-map-overrides.css";
import { render, h } from "preact";
import FullUI from "./full-ui.component";
import Popup from "./popup.component";
Expand Down Expand Up @@ -36,11 +36,15 @@ function preactCustomElement(Comp, observedAttributes = []) {
this.renderWithPreact();
}
renderWithPreact() {
this.shadow = this.attachShadow({ mode: "open" });
this.renderedEl = render(
h(Comp, { customElement: this }),
this,
this.shadow,
this.renderedEl
);
const style = document.createElement("style");
style.textContent = styles.toString();
this.shadow.appendChild(style);
}
};
}

0 comments on commit 62384b1

Please sign in to comment.