From 1346fa2c776d29a1eb44fba3904037ab06714c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Tue, 7 May 2024 12:48:06 +0300 Subject: [PATCH 1/2] Fixed #15472 -Tooltip | Tooltip-option tooltipEvent=focus does not work on p-button --- src/app/components/tooltip/tooltip.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/components/tooltip/tooltip.ts b/src/app/components/tooltip/tooltip.ts index 043a70a7bc1..9cb2b3adb42 100755 --- a/src/app/components/tooltip/tooltip.ts +++ b/src/app/components/tooltip/tooltip.ts @@ -180,7 +180,11 @@ 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); + let target = this.el.nativeElement.querySelector('.p-component'); + if (!target) { + target = this.el.nativeElement; + } + target.addEventListener('focus', this.focusListener); target.addEventListener('blur', this.blurListener); } @@ -638,7 +642,11 @@ export class Tooltip implements AfterViewInit, OnDestroy { 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); + let target = this.el.nativeElement.querySelector('.p-component'); + + if (!target) { + target = this.el.nativeElement; + } target.removeEventListener('focus', this.focusListener); target.removeEventListener('blur', this.blurListener); @@ -703,3 +711,4 @@ export class Tooltip implements AfterViewInit, OnDestroy { declarations: [Tooltip] }) export class TooltipModule {} + From 11b851e46ea251c74ebeb07d7d48589599016e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Thu, 9 May 2024 13:42:14 +0300 Subject: [PATCH 2/2] refactor --- src/app/components/tooltip/tooltip.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/app/components/tooltip/tooltip.ts b/src/app/components/tooltip/tooltip.ts index 9cb2b3adb42..4f31569d393 100755 --- a/src/app/components/tooltip/tooltip.ts +++ b/src/app/components/tooltip/tooltip.ts @@ -169,20 +169,24 @@ export class Tooltip implements AfterViewInit, OnDestroy { ngAfterViewInit() { if (isPlatformBrowser(this.platformId)) { this.zone.runOutsideAngular(() => { - if (this.getOption('tooltipEvent') === 'hover') { + const tooltipEvent = this.getOption('tooltipEvent'); + + if (tooltipEvent === 'hover' || tooltipEvent === 'both') { this.mouseEnterListener = this.onMouseEnter.bind(this); this.mouseLeaveListener = this.onMouseLeave.bind(this); this.clickListener = this.onInputClick.bind(this); this.el.nativeElement.addEventListener('mouseenter', this.mouseEnterListener); this.el.nativeElement.addEventListener('click', this.clickListener); this.el.nativeElement.addEventListener('mouseleave', this.mouseLeaveListener); - } else if (this.getOption('tooltipEvent') === 'focus') { + } + if (tooltipEvent === 'focus' || tooltipEvent === 'both') { this.focusListener = this.onFocus.bind(this); this.blurListener = this.onBlur.bind(this); let target = this.el.nativeElement.querySelector('.p-component'); + if (!target) { - target = this.el.nativeElement; + target = this.getTarget(this.el.nativeElement); } target.addEventListener('focus', this.focusListener); @@ -637,21 +641,23 @@ export class Tooltip implements AfterViewInit, OnDestroy { } unbindEvents() { - if (this.getOption('tooltipEvent') === 'hover') { + const tooltipEvent = this.getOption('tooltipEvent'); + + if (tooltipEvent === 'hover' || tooltipEvent === 'both') { 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') { + } + if (tooltipEvent === 'focus' || tooltipEvent === 'both') { let target = this.el.nativeElement.querySelector('.p-component'); if (!target) { - target = this.el.nativeElement; + target = this.getTarget(this.el.nativeElement); } target.removeEventListener('focus', this.focusListener); target.removeEventListener('blur', this.blurListener); } - this.unbindDocumentResizeListener(); } @@ -711,4 +717,3 @@ export class Tooltip implements AfterViewInit, OnDestroy { declarations: [Tooltip] }) export class TooltipModule {} -