Skip to content

Commit 3825429

Browse files
authored
Merge pull request #657 from HelixDesignSystem/v0.18.x-fix-ShadyCSS-styleElement
[v0.18.x] fix(HXElement): call ShadyCSS away from constructor
2 parents 09a3ce7 + dbc5600 commit 3825429

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/interfaces/HXElement/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class HXElement extends HTMLElement {
111111
this._$tabIndex = this.getAttribute('tabindex');
112112
this.$upgradeProperty('disabled');
113113
this.setAttribute('hx-defined', '');
114+
this._$styleElement();
114115
this.$onConnect();
115116
}
116117

@@ -317,10 +318,23 @@ export class HXElement extends HTMLElement {
317318
if (this.constructor.template) {
318319
let _template = this._$prepareTemplate(this.constructor.template);
319320
this.attachShadow({ mode: 'open' });
320-
if (window.ShadyCSS) {
321-
ShadyCSS.styleElement(this);
322-
}
323321
this.shadowRoot.appendChild(_template.content.cloneNode(true));
324322
}
325323
}//_$setupShadowDOM()
324+
325+
/**
326+
* @description
327+
* Style the element using ShadyCSS, if needed.
328+
*
329+
* @note: has the potential to modify the `[class]` attribute
330+
* of the element, so avoid running in the constructor.
331+
*/
332+
_$styleElement () {
333+
// short circuit if browser natively supports ShadowDOM
334+
if (!window.ShadyCSS) {
335+
return;
336+
}
337+
338+
ShadyCSS.styleElement(this);
339+
}
326340
}

0 commit comments

Comments
 (0)