Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function noShadowDOM() {

export function createElementType<T>(
BaseElement: typeof HTMLElement,
propDefinition: PropsDefinition<T>
propDefinition: PropsDefinition<T>,
{ nestedCustomElements = window.customElements }: { nestedCustomElements?: CustomElementRegistry; }
) {
const propKeys = Object.keys(propDefinition) as Array<
keyof PropsDefinition<T>
Expand Down Expand Up @@ -59,7 +60,7 @@ export function createElementType<T>(
const props = propValues<T>(this.props as PropsDefinition<T>),
ComponentType = this.Component as
| Function
| { new (...args: any[]): any },
| { new(...args: any[]): any },
outerElement = currentElement;
try {
currentElement = this;
Expand Down Expand Up @@ -108,7 +109,13 @@ export function createElementType<T>(
}

get renderRoot() {
return this.shadowRoot || this.attachShadow({ mode: "open" });
return this.shadowRoot || (() => {
try {
return this.attachShadow({ mode: 'open', registry: nestedCustomElements } as any)
} catch (err) {
return this.attachShadow({ mode: 'open' })
}
})();
}

addReleaseCallback(fn: () => void) {
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type RegisterOptions = {
BaseElement?: typeof HTMLElement;
extension?: { extends: string };
customElements?: CustomElementRegistry;
nestedCustomElements?: CustomElementRegistry;
};
export type PropDefinition<T> = uPropDefinition<T>;

Expand All @@ -31,7 +32,8 @@ export function register<T>(
const {
BaseElement = HTMLElement,
extension,
customElements = window.customElements
customElements = window.customElements,
nestedCustomElements = customElements,
} = options;
return (ComponentType: ComponentType<T>) => {
if (!tag) throw new Error("tag is required to register a Component");
Expand All @@ -42,7 +44,7 @@ export function register<T>(
return ElementType;
}

ElementType = createElementType(BaseElement, normalizePropDefs(props));
ElementType = createElementType(BaseElement, normalizePropDefs(props),{nestedCustomElements});
ElementType.prototype.Component = ComponentType;
ElementType.prototype.registeredTag = tag;
customElements.define(tag, ElementType, extension);
Expand Down