Skip to content

Commit

Permalink
feat: add possibility to set nativeEl
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Jul 3, 2022
1 parent b2e8c90 commit 278d922
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.js
Expand Up @@ -143,6 +143,7 @@ export const SuperMediaMixin = (superclass, { tag, is }) => {
#isInit;
#loadComplete;
#isLoaded = false;
#nativeEl;
#standinEl;

constructor() {
Expand Down Expand Up @@ -176,7 +177,11 @@ export const SuperMediaMixin = (superclass, { tag, is }) => {
}

get nativeEl() {
return this.shadowRoot.querySelector(tag);
return this.#nativeEl ?? this.shadowRoot.querySelector(tag);
}

set nativeEl(val) {
this.#nativeEl = val;
}

#initStandinEl() {
Expand Down Expand Up @@ -231,7 +236,7 @@ export const SuperMediaMixin = (superclass, { tag, is }) => {
childMap.set(el, clone);
}
if (this.loadComplete && !this.isLoaded) await this.loadComplete;
this.nativeEl.append(clone);
this.nativeEl.append?.(clone);
});
removeNativeChildren.forEach((el) => el.remove());
});
Expand Down Expand Up @@ -325,12 +330,12 @@ export const SuperMediaMixin = (superclass, { tag, is }) => {
// When this is the original Custom Element, or the subclass doesn't
// have a matching prop, pass it through.
if (newValue === null) {
this.nativeEl.removeAttribute(attrName);
this.nativeEl.removeAttribute?.(attrName);
} else {
// Ignore a few that don't need to be passed through just in case
// it creates unexpected behavior.
if (['id', 'class'].indexOf(attrName) === -1) {
this.nativeEl.setAttribute(attrName, newValue);
this.nativeEl.setAttribute?.(attrName, newValue);
}
}
}
Expand Down

0 comments on commit 278d922

Please sign in to comment.