fix(tooltip): don't close a tooltip while a nested tooltip inside it is open
This commit is contained in:
@@ -27,6 +27,10 @@ type UnwrapInputSignals<T> = {
|
||||
standalone: true,
|
||||
})
|
||||
export class ComponentTooltipDirective<T extends object> implements OnDestroy {
|
||||
private static readonly openInstances = new Set<
|
||||
ComponentTooltipDirective<any>
|
||||
>();
|
||||
|
||||
readonly component = input.required<ComponentType<T>>({
|
||||
alias: 'appComponentTooltip',
|
||||
});
|
||||
@@ -104,13 +108,32 @@ export class ComponentTooltipDirective<T extends object> 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<T extends object> 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<T extends object> 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user