Skip to content

Commit f5a472e

Browse files
committed
feat(element): fallback where adoptedStyleSheets is not supported
1 parent e1d24e9 commit f5a472e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/element/atropos-element.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@ class AtroposComponent extends HTMLElement {
6666
`;
6767
this.shadow.innerHTML = '';
6868

69-
// eslint-disable-next-line no-restricted-globals
70-
const styleSheet = new CSSStyleSheet();
71-
styleSheet.replaceSync(styles);
72-
this.shadow.adoptedStyleSheets = [styleSheet];
69+
if (typeof CSSStyleSheet !== 'undefined' && this.shadow.adoptedStyleSheets) {
70+
// eslint-disable-next-line no-restricted-globals
71+
const styleSheet = new CSSStyleSheet();
72+
styleSheet.replaceSync(styles);
73+
this.shadow.adoptedStyleSheets = [styleSheet];
74+
} else {
75+
const styleEl = document.createElement('style');
76+
styleEl.rel = 'stylesheet';
77+
styleEl.textContent = styles;
78+
this.shadow.appendChild(styleEl);
79+
}
7380

7481
this.shadow.appendChild(el);
7582

0 commit comments

Comments
 (0)