From f69b3cf871da4a691864351aac3e7ba18d1b23fd Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 17 Aug 2026 20:23:48 +0200 Subject: [PATCH] fix(tooltip): don't close a tooltip while a nested tooltip inside it is open --- .../directives/component-tooltip.directive.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/webapp/src/app/directives/component-tooltip.directive.ts b/webapp/src/app/directives/component-tooltip.directive.ts index 2f9e8735..7fc7d482 100644 --- a/webapp/src/app/directives/component-tooltip.directive.ts +++ b/webapp/src/app/directives/component-tooltip.directive.ts @@ -27,6 +27,10 @@ type UnwrapInputSignals = { standalone: true, }) export class ComponentTooltipDirective implements OnDestroy { + private static readonly openInstances = new Set< + ComponentTooltipDirective + >(); + readonly component = input.required>({ alias: 'appComponentTooltip', }); @@ -104,13 +108,32 @@ export class ComponentTooltipDirective implements OnDestroy { } private scheduleHide(): void { + clearTimeout(this.hideTimeout); this.hideTimeout = setTimeout(() => { - if (!this.isOverHost && !this.isOverOverlay) { - this.hide(); + if (this.isOverHost || this.isOverOverlay) { + return; } + if (this.hasOpenDescendantTooltip()) { + this.scheduleHide(); + return; + } + this.hide(); }, this.tooltipHideDelay()); } + private hasOpenDescendantTooltip(): boolean { + const paneElement = this.overlayRef?.overlayElement; + if (!paneElement) return false; + + for (const other of ComponentTooltipDirective.openInstances) { + if (other === this) continue; + if (paneElement.contains(other.elementRef.nativeElement)) { + return true; + } + } + return false; + } + private show(): void { if (this.overlayRef?.hasAttached()) return; @@ -175,6 +198,8 @@ export class ComponentTooltipDirective implements OnDestroy { overlayElement.addEventListener('mouseenter', this.onOverlayEnter); overlayElement.addEventListener('mouseleave', this.onOverlayLeave); overlayElement.addEventListener('click', this.onOverlayClick, true); + + ComponentTooltipDirective.openInstances.add(this); } private applyMaxWidth( @@ -212,12 +237,14 @@ export class ComponentTooltipDirective implements OnDestroy { this.overlayRef.detach(); } this.componentRef = null; + ComponentTooltipDirective.openInstances.delete(this); } ngOnDestroy(): void { clearTimeout(this.showTimeout); clearTimeout(this.hideTimeout); clearTimeout(this.dismissTimeout); + ComponentTooltipDirective.openInstances.delete(this); this.overlayRef?.dispose(); } }