From 6ce9c948fb59f491bb324a6200fdf16605b549c1 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 4 Nov 2022 13:52:09 +0000 Subject: [PATCH] Refactor #12031 - Add two-way binding to visible option --- src/app/components/overlay/overlay.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/components/overlay/overlay.ts b/src/app/components/overlay/overlay.ts index 89acf31f30c..58e1238f9a6 100644 --- a/src/app/components/overlay/overlay.ts +++ b/src/app/components/overlay/overlay.ts @@ -156,6 +156,8 @@ export class Overlay implements OnDestroy { this._options = val; } + @Output() visibleChange: EventEmitter = new EventEmitter(); + @Output() onBeforeShow: EventEmitter = new EventEmitter(); @Output() onShow: EventEmitter = new EventEmitter(); @@ -252,7 +254,7 @@ export class Overlay implements OnDestroy { } show(overlay?: HTMLElement, isFocus: boolean = false) { - this.visible = true; + this.onVisibleChange(true); this.handleEvents('onShow', { overlay: overlay || this.overlayEl, target: this.targetEl, mode: this.overlayMode }); isFocus && DomHandler.focus(this.targetEl); @@ -260,13 +262,18 @@ export class Overlay implements OnDestroy { } hide(overlay?: HTMLElement, isFocus: boolean = false) { - this.visible = false; + this.onVisibleChange(false); this.handleEvents('onHide', { overlay: overlay || this.overlayEl, target: this.targetEl, mode: this.overlayMode }); isFocus && DomHandler.focus(this.targetEl); this.modal && DomHandler.removeClass(this.document?.body, 'p-overflow-hidden'); } + onVisibleChange(visible: boolean) { + this._visible = visible; + this.visibleChange.emit(visible); + } + alignOverlay() { !this.modal && DomHandler.alignOverlay(this.overlayEl, this.targetEl, this.appendTo); }