From 1d11963d0e1b0e670ecff4b7aa6abcdd01ca9fb8 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 8 Mar 2023 16:20:12 +0100 Subject: [PATCH] append modal element at correct child element --- .../libs/modal/modal-handler.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/libs/modal/modal-handler.ts b/src/Umbraco.Web.UI.Client/libs/modal/modal-handler.ts index 4dbbb68bf3..742d83c2b1 100644 --- a/src/Umbraco.Web.UI.Client/libs/modal/modal-handler.ts +++ b/src/Umbraco.Web.UI.Client/libs/modal/modal-handler.ts @@ -1,6 +1,6 @@ import type { UUIDialogElement } from '@umbraco-ui/uui'; import type { UUIModalDialogElement } from '@umbraco-ui/uui-modal-dialog'; -import type { UUIModalSidebarElement, UUIModalSidebarSize } from '@umbraco-ui/uui-modal-sidebar'; +import { UUIModalSidebarElement, UUIModalSidebarSize } from '@umbraco-ui/uui-modal-sidebar'; import { v4 as uuidv4 } from 'uuid'; import { BehaviorSubject } from 'rxjs'; import { UmbModalConfig, UmbModalType } from './modal.context'; @@ -18,9 +18,11 @@ export class UmbModalHandler { public containerElement: UUIModalDialogElement | UUIModalSidebarElement; - #element = new BehaviorSubject(undefined); + #element = new BehaviorSubject(undefined); public readonly element = this.#element.asObservable(); + #innerElement?: UUIModalSidebarElement | UUIDialogElement; + public key: string; public type: UmbModalType = 'dialog'; public size: UUIModalSidebarSize = 'small'; @@ -57,6 +59,7 @@ export class UmbModalHandler { #createSidebarElement() { const sidebarElement = document.createElement('uui-modal-sidebar'); + this.#innerElement = sidebarElement; sidebarElement.size = this.size; return sidebarElement; } @@ -64,6 +67,7 @@ export class UmbModalHandler { #createDialogElement() { const modalDialogElement = document.createElement('uui-modal-dialog'); const dialogElement: UUIDialogElement = document.createElement('uui-dialog'); + this.#innerElement = dialogElement; modalDialogElement.appendChild(dialogElement); return modalDialogElement; } @@ -100,12 +104,23 @@ export class UmbModalHandler { async (manifest) => { if (manifest) { const element = await this.#createLayoutElement(manifest, data); + this.#appendModalElement(element); this.#element.next(element); - this.containerElement.appendChild(element); } else { + this.#removeModalElement(); this.#element.next(undefined); } } ); } + + #appendModalElement(element: any) { + this.#innerElement?.appendChild(element); + } + + #removeModalElement() { + if (this.#element.getValue()) { + this.#innerElement?.removeChild(this.#element.getValue()); + } + } }