1
1
import {
2
2
Directive , ElementRef , HostListener , Input , NgModule , ChangeDetectorRef , OnInit ,
3
- Output , EventEmitter , Optional , HostBinding , Inject
3
+ Output , EventEmitter , Optional , HostBinding , Inject , OnDestroy
4
4
} from '@angular/core' ;
5
5
import { useAnimation } from '@angular/animations' ;
6
6
import { scaleInCenter } from '../../animations/scale/index' ;
@@ -11,6 +11,8 @@ import { CommonModule } from '@angular/common';
11
11
import { IgxNavigationService } from '../../core/navigation' ;
12
12
import { IgxToggleDirective , IgxToggleActionDirective } from '../toggle/toggle.directive' ;
13
13
import { IBaseEventArgs } from '../../core/utils' ;
14
+ import { Subject } from 'rxjs' ;
15
+ import { takeUntil } from 'rxjs/operators' ;
14
16
15
17
export interface ITooltipShowEventArgs extends IBaseEventArgs {
16
18
target : IgxTooltipTargetDirective ;
@@ -41,7 +43,9 @@ export interface ITooltipHideEventArgs extends IBaseEventArgs {
41
43
exportAs : 'tooltipTarget' ,
42
44
selector : '[igxTooltipTarget]'
43
45
} )
44
- export class IgxTooltipTargetDirective extends IgxToggleActionDirective implements OnInit {
46
+ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implements OnInit , OnDestroy {
47
+ private destroy$ = new Subject ( ) ;
48
+
45
49
/**
46
50
* Gets/sets the amount of milliseconds that should pass before showing the tooltip.
47
51
*
@@ -196,6 +200,24 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
196
200
197
201
this . _overlayDefaults . positionStrategy = new AutoPositionStrategy ( positionSettings ) ;
198
202
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 ( ) ;
199
221
}
200
222
201
223
private checkOutletAndOutsideClick ( ) {
@@ -220,13 +242,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
220
242
if ( ! this . target . collapsed || this . target . toBeHidden ) {
221
243
clearTimeout ( this . target . timeoutId ) ;
222
244
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
-
230
245
// if close animation has started finish it, or close the tooltip with no animation
231
246
this . target . forceClose ( this . mergedOverlaySettings ) ;
232
247
this . target . toBeHidden = false ;
@@ -249,36 +264,12 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
249
264
return false ;
250
265
}
251
266
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
-
269
267
/**
270
268
* @hidden
271
269
*/
272
270
@HostListener ( 'click' )
273
271
public onClick ( ) {
274
272
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
-
282
273
this . target . forceClose ( this . mergedOverlaySettings ) ;
283
274
}
284
275
}
@@ -327,18 +318,13 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
327
318
return ;
328
319
}
329
320
330
- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
331
- this . onTooltipHide . emit ( hidingArgs ) ;
332
-
333
- if ( hidingArgs . cancel ) {
334
- return ;
335
- }
336
-
337
321
this . target . toBeHidden = true ;
338
322
this . target . timeoutId = setTimeout ( ( ) => {
339
323
this . target . close ( ) ; // Call close() of IgxTooltipDirective
340
324
this . target . toBeHidden = false ;
341
325
} , this . hideDelay ) ;
326
+
327
+
342
328
}
343
329
344
330
/**
@@ -380,12 +366,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
380
366
clearTimeout ( this . target . timeoutId ) ;
381
367
382
368
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
- }
389
369
// if close animation has started finish it, or close the tooltip with no animation
390
370
this . target . forceClose ( this . mergedOverlaySettings ) ;
391
371
this . target . toBeHidden = false ;
@@ -421,13 +401,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
421
401
return ;
422
402
}
423
403
424
- const hidingArgs = { target : this , tooltip : this . target , cancel : false } ;
425
- this . onTooltipHide . emit ( hidingArgs ) ;
426
-
427
- if ( hidingArgs . cancel ) {
428
- return ;
429
- }
430
-
431
404
this . target . toBeHidden = true ;
432
405
this . target . timeoutId = setTimeout ( ( ) => {
433
406
this . target . close ( ) ; // Call close() of IgxTooltipDirective
0 commit comments