From 3da4b6877f8b33439e19c48626fccd7ef6e33b5a Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Fri, 19 Apr 2019 18:31:21 +0800 Subject: [PATCH] fix(module:modal): integration problem with select component (#3245) * fix(module:modal): integration problem with select component close #3213 * style: fix lint --- components/modal/modal-util.ts | 24 ------------------------ components/modal/nz-modal.component.html | 4 ++-- components/modal/nz-modal.component.ts | 13 +++++++------ 3 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 components/modal/modal-util.ts diff --git a/components/modal/modal-util.ts b/components/modal/modal-util.ts deleted file mode 100644 index 25204954e1a..00000000000 --- a/components/modal/modal-util.ts +++ /dev/null @@ -1,24 +0,0 @@ -export interface ClickPosition { - x: number; - y: number; -} - -export class ModalUtil { - private lastPosition: ClickPosition | null = null; - - constructor(private document: Document) { - this.listenDocumentClick(); - } - - getLastClickPosition(): ClickPosition | null { - return this.lastPosition; - } - - listenDocumentClick(): void { - this.document.addEventListener('click', (event: MouseEvent) => { - this.lastPosition = { x: event.clientX, y: event.clientY }; - }); - } -} - -export default new ModalUtil(document); diff --git a/components/modal/nz-modal.component.html b/components/modal/nz-modal.component.html index 8f85e3e2616..10cb898d99f 100644 --- a/components/modal/nz-modal.component.html +++ b/components/modal/nz-modal.component.html @@ -30,7 +30,7 @@ - + @@ -100,7 +100,7 @@
- +
diff --git a/components/modal/nz-modal.component.ts b/components/modal/nz-modal.component.ts index e562d9f0977..7cd34cb5fc9 100644 --- a/components/modal/nz-modal.component.ts +++ b/components/modal/nz-modal.component.ts @@ -30,10 +30,9 @@ import { import { fromEvent, Observable, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; -import { isPromise, InputBoolean } from 'ng-zorro-antd/core'; +import { getElementOffset, isPromise, InputBoolean } from 'ng-zorro-antd/core'; import { NzI18nService } from 'ng-zorro-antd/i18n'; -import ModalUtil from './modal-util'; import { NzModalConfig, NZ_MODAL_CONFIG } from './nz-modal-config'; import { NzModalControlService } from './nz-modal-control.service'; import { NzModalRef } from './nz-modal-ref.class'; @@ -472,10 +471,12 @@ export class NzModalComponent extends NzModalRef // Update transform-origin to the last click position on document private updateTransformOrigin(): void { const modalElement = this.modalContainer.nativeElement as HTMLElement; - const lastPosition = ModalUtil.getLastClickPosition(); - if (lastPosition) { - this.transformOrigin = `${lastPosition.x - modalElement.offsetLeft}px ${lastPosition.y - - modalElement.offsetTop}px 0px`; + if (this.previouslyFocusedElement) { + const previouslyDOMRect = this.previouslyFocusedElement.getBoundingClientRect(); + const lastPosition = getElementOffset(this.previouslyFocusedElement); + const x = lastPosition.left + previouslyDOMRect.width / 2; + const y = lastPosition.top + previouslyDOMRect.height / 2; + this.transformOrigin = `${x - modalElement.offsetLeft}px ${y - modalElement.offsetTop}px 0px`; } }