From dba960c4549fc317263bcaeaac7e85f67f646c1e Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Wed, 13 May 2026 10:59:51 +0330 Subject: [PATCH] feat: implement lifecycle hooks for light bottomsheet component to manage DOM positioning --- .../dialog/light-bottomsheet.component.ts | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/app/shared/components/dialog/light-bottomsheet.component.ts b/src/app/shared/components/dialog/light-bottomsheet.component.ts index 715767d..5d5ce89 100644 --- a/src/app/shared/components/dialog/light-bottomsheet.component.ts +++ b/src/app/shared/components/dialog/light-bottomsheet.component.ts @@ -1,5 +1,16 @@ import { NgStyle } from '@angular/common'; -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { DOCUMENT } from '@angular/common'; +import { + Component, + ElementRef, + EventEmitter, + Inject, + Input, + OnDestroy, + OnInit, + Output, + Renderer2, +} from '@angular/core'; @Component({ selector: 'shared-light-bottomsheet', @@ -91,7 +102,7 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; '[style.--sheet-transition]': 'transitionOptions', }, }) -export class SharedLightBottomsheetComponent { +export class SharedLightBottomsheetComponent implements OnInit, OnDestroy { @Input() header = ''; @Input() visible = false; @Output() visibleChange = new EventEmitter(); @@ -104,6 +115,27 @@ export class SharedLightBottomsheetComponent { @Output() onHide = new EventEmitter(); + private originalParent: Node | null = null; + + constructor( + private readonly elementRef: ElementRef, + private readonly renderer: Renderer2, + @Inject(DOCUMENT) private readonly document: Document, + ) {} + + ngOnInit() { + const host = this.elementRef.nativeElement; + this.originalParent = host.parentNode; + this.renderer.appendChild(this.document.body, host); + } + + ngOnDestroy() { + const host = this.elementRef.nativeElement; + if (this.originalParent) { + this.renderer.appendChild(this.originalParent, host); + } + } + onVisibilityChange(nextValue: boolean) { this.visible = nextValue; this.visibleChange.emit(nextValue);