diff --git a/src/app/components/tooltip/tooltip.ts b/src/app/components/tooltip/tooltip.ts index 043a70a7bc1..95ab90f6a28 100755 --- a/src/app/components/tooltip/tooltip.ts +++ b/src/app/components/tooltip/tooltip.ts @@ -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 @@ -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); @@ -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);