Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(overlays): presenting an overlay does not create nested elements #26154

Merged
merged 10 commits into from
Nov 2, 2022
28 changes: 17 additions & 11 deletions core/src/utils/framework-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export const CoreDelegate = () => {
userComponentProps: any = {},
cssClasses: string[] = []
) => {
const hasUserDefinedComponent = userComponent !== undefined;

BaseComponent = parentElement;
/**
* If passing in a component via the `component` props
Expand Down Expand Up @@ -88,15 +86,23 @@ export const CoreDelegate = () => {
BaseComponent.appendChild(el);

await new Promise((resolve) => componentOnReady(el, resolve));
} else if (hasUserDefinedComponent && BaseComponent.children.length > 0) {
// If there is no component, then we need to create a new parent
// element to apply the css classes to.
const el = BaseComponent.ownerDocument?.createElement('div');
cssClasses.forEach((c) => el.classList.add(c));
// Move each child from the original template to the new parent element.
el.append(...BaseComponent.children);
// Append the new parent element to the original parent element.
BaseComponent.appendChild(el);
} else if (BaseComponent.children.length > 0) {
const root = BaseComponent.children[0] as HTMLElement & { __delegateHost?: boolean };
if (root.__delegateHost !== true) {
/**
* If the root element is not a delegate host, it means
* that the overlay has not been presented yet and we need
* to create the containing element with the specified classes.
*/
const el = BaseComponent.ownerDocument?.createElement('div');
// Internal flag to track if the element is a delegate host
el.__delegateHost = true;
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
cssClasses.forEach((c) => el.classList.add(c));
// Move each child from the original template to the new parent element.
el.append(...BaseComponent.children);
// Append the new parent element to the original parent element.
BaseComponent.appendChild(el);
}
}

/**
Expand Down