Skip to content

Commit

Permalink
Merge pull request #15469 from primefaces/issue-15468
Browse files Browse the repository at this point in the history
Fixed #15468 - Tooltip | tooltipEvent - focus | hover combined
  • Loading branch information
cetincakiroglu authored May 9, 2024
2 parents edcd42f + 7ce0541 commit 2217228
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/app/components/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Tooltip implements AfterViewInit, OnDestroy {
* Event to show the tooltip.
* @group Props
*/
@Input() tooltipEvent: 'hover' | 'focus' | string | any = 'hover';
@Input() tooltipEvent: 'hover' | 'focus' | 'both' | string | any = 'hover';
/**
* Target element to attach the overlay, valid values are "body", "target" or a local ng-F variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
* @group Props
Expand Down Expand Up @@ -169,14 +169,17 @@ 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);

Expand Down Expand Up @@ -633,11 +636,14 @@ 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.getTarget(this.el.nativeElement);

target.removeEventListener('focus', this.focusListener);
Expand Down

0 comments on commit 2217228

Please sign in to comment.