diff --git a/alfa-client/libs/design-system/src/lib/tooltip/tooltip.directive.ts b/alfa-client/libs/design-system/src/lib/tooltip/tooltip.directive.ts index 75d6524111e0f8f052924cb96bf065a7dd52f55d..f4ee72567dfe69aae0263afad8fc95e13d26b99d 100644 --- a/alfa-client/libs/design-system/src/lib/tooltip/tooltip.directive.ts +++ b/alfa-client/libs/design-system/src/lib/tooltip/tooltip.directive.ts @@ -39,7 +39,10 @@ export class TooltipDirective implements OnDestroy { @HostListener('mouseenter') @HostListener('focusin') createTooltip(): void { - if (isNotNull(this.componentRef)) return; + if (isNotNull(this.componentRef)) { + return; + } + const nativeElement: HTMLElement = this.elementRef.nativeElement; const attachedToFocused: boolean = nativeElement.contains(document.activeElement); this.componentRef = this.viewContainerRef.createComponent(TooltipComponent); @@ -63,7 +66,10 @@ export class TooltipDirective implements OnDestroy { } setTooltipProperties(attachedToFocused = false): void { - if (isNull(this.componentRef)) return; + if (isNull(this.componentRef)) { + return; + } + const { left, right, bottom } = this.elementRef.nativeElement.getBoundingClientRect(); this.componentRef.instance.left = (right + left) / 2; this.componentRef.instance.top = attachedToFocused ? bottom + OUTLINE_INDENT : bottom; @@ -88,7 +94,10 @@ export class TooltipDirective implements OnDestroy { } destroy(): void { - if (isNull(this.componentRef)) return; + if (isNull(this.componentRef)) { + return; + } + this.componentRef.destroy(); this.componentRef = null; this.removeAriaDescribedBy();