From f3bdfe02ada19ab39b45084447fdfd847486c274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Wed, 27 Dec 2023 18:24:15 +0300 Subject: [PATCH] Fixed #14264 - Tooltip | Cannot read properties of null (reading 'addEventListener') if tooltipEvent is of type focus --- src/app/components/tooltip/tooltip.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/components/tooltip/tooltip.ts b/src/app/components/tooltip/tooltip.ts index 4dec559b8c0..b999b5a1425 100755 --- a/src/app/components/tooltip/tooltip.ts +++ b/src/app/components/tooltip/tooltip.ts @@ -180,7 +180,9 @@ export class Tooltip implements AfterViewInit, OnDestroy { this.focusListener = this.onFocus.bind(this); this.blurListener = this.onBlur.bind(this); - let target = this.getTarget(this.el.nativeElement); + const targetElement = this.el.nativeElement; + const defaultTarget = DomHandler.getFocusableElements(targetElement)[0]; + const target = this.getTarget(targetElement) || this.getTarget(defaultTarget); target.addEventListener('focus', this.focusListener); target.addEventListener('blur', this.blurListener); } @@ -637,9 +639,13 @@ export class Tooltip implements AfterViewInit, OnDestroy { this.el.nativeElement.removeEventListener('mouseenter', this.mouseEnterListener); this.el.nativeElement.removeEventListener('mouseleave', this.mouseLeaveListener); this.el.nativeElement.removeEventListener('click', this.clickListener); - } else if (this.getOption('tooltipEvent') === 'focus') { - let target = this.getTarget(this.el.nativeElement); - + } + + else if (this.getOption('tooltipEvent') === 'focus') { + const targetElement = this.el.nativeElement; + const defaultTarget = DomHandler.getFocusableElements(targetElement)[0]; + const target = this.getTarget(targetElement) || this.getTarget(defaultTarget); + target.removeEventListener('focus', this.focusListener); target.removeEventListener('blur', this.blurListener); } @@ -703,3 +709,4 @@ export class Tooltip implements AfterViewInit, OnDestroy { declarations: [Tooltip] }) export class TooltipModule {} +