11import {
22 Directive , ElementRef , HostListener , Input , NgModule , ChangeDetectorRef , OnInit ,
3- Output , EventEmitter , Optional , HostBinding , Inject
3+ Output , EventEmitter , Optional , HostBinding , Inject , OnDestroy
44} from '@angular/core' ;
55import { useAnimation } from '@angular/animations' ;
66import { scaleInCenter } from '../../animations/scale/index' ;
@@ -11,6 +11,8 @@ import { CommonModule } from '@angular/common';
1111import { IgxNavigationService } from '../../core/navigation' ;
1212import { IgxToggleDirective , IgxToggleActionDirective } from '../toggle/toggle.directive' ;
1313import { IBaseEventArgs } from '../../core/utils' ;
14+ import { Subject } from 'rxjs' ;
15+ import { takeUntil } from 'rxjs/operators' ;
1416
1517export interface ITooltipShowEventArgs extends IBaseEventArgs {
1618 target : IgxTooltipTargetDirective ;
@@ -41,7 +43,9 @@ export interface ITooltipHideEventArgs extends IBaseEventArgs {
4143 exportAs : 'tooltipTarget' ,
4244 selector : '[igxTooltipTarget]'
4345} )
44- export class IgxTooltipTargetDirective extends IgxToggleActionDirective implements OnInit {
46+ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implements OnInit , OnDestroy {
47+ private destroy$ = new Subject ( ) ;
48+
4549 /**
4650 * Gets/sets the amount of milliseconds that should pass before showing the tooltip.
4751 *
@@ -196,6 +200,24 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
196200
197201 this . _overlayDefaults . positionStrategy = new AutoPositionStrategy ( positionSettings ) ;
198202 this . _overlayDefaults . closeOnOutsideClick = false ;
203+ this . _overlayDefaults . closeOnEscape = true ;
204+
205+ this . target . onClosing . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( event ) => {
206+ const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
207+ this . onTooltipHide . emit ( hidingArgs ) ;
208+
209+ if ( hidingArgs . cancel ) {
210+ event . cancel = true ;
211+ }
212+ } ) ;
213+ }
214+
215+ /**
216+ * @hidden
217+ */
218+ ngOnDestroy ( ) {
219+ this . destroy$ . next ( ) ;
220+ this . destroy$ . complete ( ) ;
199221 }
200222
201223 private checkOutletAndOutsideClick ( ) {
@@ -220,13 +242,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
220242 if ( ! this . target . collapsed || this . target . toBeHidden ) {
221243 clearTimeout ( this . target . timeoutId ) ;
222244
223- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
224- this . onTooltipHide . emit ( hidingArgs ) ;
225-
226- if ( hidingArgs . cancel ) {
227- return true ;
228- }
229-
230245 // if close animation has started finish it, or close the tooltip with no animation
231246 this . target . forceClose ( this . mergedOverlaySettings ) ;
232247 this . target . toBeHidden = false ;
@@ -249,36 +264,12 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
249264 return false ;
250265 }
251266
252- /**
253- * @hidden
254- */
255- @HostListener ( 'document:keydown.escape' , [ '$event' ] )
256- public onKeydownEscape ( event ) {
257- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
258- this . onTooltipHide . emit ( hidingArgs ) ;
259-
260- if ( hidingArgs . cancel ) {
261- return ;
262- }
263-
264- this . target . toBeHidden = true ;
265- this . target . close ( ) ;
266- this . target . toBeHidden = false ;
267- }
268-
269267 /**
270268 * @hidden
271269 */
272270 @HostListener ( 'click' )
273271 public onClick ( ) {
274272 if ( ! this . target . collapsed ) {
275- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
276- this . onTooltipHide . emit ( hidingArgs ) ;
277-
278- if ( hidingArgs . cancel ) {
279- return ;
280- }
281-
282273 this . target . forceClose ( this . mergedOverlaySettings ) ;
283274 }
284275 }
@@ -327,18 +318,13 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
327318 return ;
328319 }
329320
330- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
331- this . onTooltipHide . emit ( hidingArgs ) ;
332-
333- if ( hidingArgs . cancel ) {
334- return ;
335- }
336-
337321 this . target . toBeHidden = true ;
338322 this . target . timeoutId = setTimeout ( ( ) => {
339323 this . target . close ( ) ; // Call close() of IgxTooltipDirective
340324 this . target . toBeHidden = false ;
341325 } , this . hideDelay ) ;
326+
327+
342328 }
343329
344330 /**
@@ -380,12 +366,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
380366 clearTimeout ( this . target . timeoutId ) ;
381367
382368 if ( ! this . target . collapsed ) {
383- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
384- this . onTooltipHide . emit ( hidingArgs ) ;
385-
386- if ( hidingArgs . cancel ) {
387- return ;
388- }
389369 // if close animation has started finish it, or close the tooltip with no animation
390370 this . target . forceClose ( this . mergedOverlaySettings ) ;
391371 this . target . toBeHidden = false ;
@@ -421,13 +401,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
421401 return ;
422402 }
423403
424- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
425- this . onTooltipHide . emit ( hidingArgs ) ;
426-
427- if ( hidingArgs . cancel ) {
428- return ;
429- }
430-
431404 this . target . toBeHidden = true ;
432405 this . target . timeoutId = setTimeout ( ( ) => {
433406 this . target . close ( ) ; // Call close() of IgxTooltipDirective
0 commit comments