diff --git a/packages/core/src/components/modal-container/modal-container.tsx b/packages/core/src/components/modal-container/modal-container.tsx index 8544b0af017..5e01c6492ec 100644 --- a/packages/core/src/components/modal-container/modal-container.tsx +++ b/packages/core/src/components/modal-container/modal-container.tsx @@ -19,6 +19,10 @@ import { TypedEvent } from '../utils/typed-event'; export class ModalContainer { @Element() hostElement: HTMLIxModalContainerElement; + get modalStack() { + return this.hostElement.querySelector(':scope > div.modal-stack'); + } + /** * Display modal dialog * @@ -41,15 +45,18 @@ export class ModalContainer { } else { modal.appendChild(content); } - - this.hostElement.appendChild(modal); + this.modalStack.appendChild(modal); modal.addEventListener('closed', (event: CustomEvent) => { - this.hostElement.removeChild(modal); + event.preventDefault(); + event.stopImmediatePropagation(); + this.modalStack.removeChild(modal); onClose.emit(event.detail); }); modal.addEventListener('dismissed', (event: CustomEvent) => { - this.hostElement.removeChild(modal); + event.preventDefault(); + event.stopImmediatePropagation(); + this.modalStack.removeChild(modal); onDismiss.emit(event.detail); }); @@ -61,6 +68,10 @@ export class ModalContainer { } render() { - return ; + return ( + + + + ); } } diff --git a/packages/core/src/components/modal-container/test/modal-container.spec.tsx b/packages/core/src/components/modal-container/test/modal-container.spec.tsx index f4e0d04fe4d..761edf31bee 100644 --- a/packages/core/src/components/modal-container/test/modal-container.spec.tsx +++ b/packages/core/src/components/modal-container/test/modal-container.spec.tsx @@ -16,6 +16,8 @@ describe('ix-modal-container', () => { components: [ModalContainer], html: '', }); - expect(page.root).toEqualHtml(''); + expect(page.root).toEqualHtml( + '' + ); }); }); diff --git a/packages/core/src/components/modal/modal.tsx b/packages/core/src/components/modal/modal.tsx index 439b5dcebb5..97ad982d4fc 100644 --- a/packages/core/src/components/modal/modal.tsx +++ b/packages/core/src/components/modal/modal.tsx @@ -21,6 +21,12 @@ import anime from 'animejs'; import Animation from '../utils/animation'; import { NotificationColor } from '../utils/notification-color'; +let modalInstanceId = 0; + +function getNextModalInstanceId() { + return `ix-modal-instance-${++modalInstanceId}`; +} + @Component({ tag: 'ix-modal', styleUrl: 'modal.scss', @@ -120,6 +126,7 @@ export class Modal { */ @Event() dismissed: EventEmitter; + private modalId = getNextModalInstanceId(); private readonly onKeydown = this.handleKeydown.bind(this); get modal() { @@ -237,7 +244,7 @@ export class Modal { render() { return ( - +
+