11import {
2- Directive , ElementRef , Input , ChangeDetectorRef , Optional , HostBinding , Inject ,
3- Output , EventEmitter
2+ Directive , ElementRef , Input , ChangeDetectorRef , Optional , HostBinding , Inject , OnDestroy
43} from '@angular/core' ;
54import { IgxOverlayService } from '../../services/overlay/overlay' ;
65import { OverlaySettings } from '../../services/public_api' ;
76import { IgxNavigationService } from '../../core/navigation' ;
87import { IgxToggleDirective } from '../toggle/toggle.directive' ;
8+ import { IgxTooltipTargetDirective } from './tooltip-target.directive' ;
9+ import { Subject , takeUntil } from 'rxjs' ;
910
1011let NEXT_ID = 0 ;
1112/**
@@ -27,7 +28,7 @@ let NEXT_ID = 0;
2728 selector : '[igxTooltip]' ,
2829 standalone : true
2930} )
30- export class IgxTooltipDirective extends IgxToggleDirective {
31+ export class IgxTooltipDirective extends IgxToggleDirective implements OnDestroy {
3132 /**
3233 * @hidden
3334 */
@@ -62,11 +63,6 @@ export class IgxTooltipDirective extends IgxToggleDirective {
6263 @Input ( )
6364 public context ;
6465
65- /**
66- * @hidden
67- */
68- @Output ( ) public forceClosed = new EventEmitter < void > ( ) ;
69-
7066 /**
7167 * Identifier for the tooltip.
7268 * If this is property is not explicitly set, it will be automatically generated.
@@ -111,7 +107,9 @@ export class IgxTooltipDirective extends IgxToggleDirective {
111107 /**
112108 * @hidden
113109 */
114- public tooltipTarget ;
110+ public tooltipTarget : IgxTooltipTargetDirective ;
111+
112+ private _destroy$ = new Subject < boolean > ( ) ;
115113
116114 /** @hidden */
117115 constructor (
@@ -121,6 +119,20 @@ export class IgxTooltipDirective extends IgxToggleDirective {
121119 @Optional ( ) navigationService : IgxNavigationService ) {
122120 // D.P. constructor duplication due to es6 compilation, might be obsolete in the future
123121 super ( elementRef , cdr , overlayService , navigationService ) ;
122+
123+ this . onDocumentTouchStart = this . onDocumentTouchStart . bind ( this ) ;
124+ this . overlayService . opening . pipe ( takeUntil ( this . _destroy$ ) ) . subscribe ( ( ) => {
125+ document . addEventListener ( 'touchstart' , this . onDocumentTouchStart , { passive : true } ) ;
126+ } ) ;
127+ this . overlayService . closed . pipe ( takeUntil ( this . _destroy$ ) ) . subscribe ( ( ) => {
128+ document . removeEventListener ( 'touchstart' , this . onDocumentTouchStart ) ;
129+ } ) ;
130+ }
131+
132+ /** @hidden */
133+ public override ngOnDestroy ( ) {
134+ super . ngOnDestroy ( ) ;
135+ document . removeEventListener ( 'touchstart' , this . onDocumentTouchStart ) ;
124136 }
125137
126138 /**
@@ -165,6 +177,10 @@ export class IgxTooltipDirective extends IgxToggleDirective {
165177 overlaySettings . positionStrategy . settings . closeAnimation = animation ;
166178 }
167179
168- this . forceClosed . emit ( ) ;
180+ document . removeEventListener ( 'touchstart' , this . onDocumentTouchStart ) ;
181+ }
182+
183+ private onDocumentTouchStart ( event ) {
184+ this . tooltipTarget ?. onDocumentTouchStart ( event ) ;
169185 }
170186}
0 commit comments