Skip to content

Commit 432c495

Browse files
committed
fix(tooltip): handle documentTouch in tooltip
1 parent 2dd570d commit 432c495

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

projects/igniteui-angular/src/lib/directives/tooltip/tooltip-target.directive.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,8 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
276276
return;
277277
}
278278

279-
const tooltipTarget = this.target.tooltipTarget?.nativeElement;
280-
281-
if (tooltipTarget &&
282-
tooltipTarget !== event.target &&
283-
!tooltipTarget.contains(event.target)
279+
if (this.nativeElement !== event.target &&
280+
!this.nativeElement.contains(event.target)
284281
) {
285282
this.hideTooltip();
286283
}
@@ -303,18 +300,11 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
303300
this._overlayDefaults.closeOnOutsideClick = false;
304301
this._overlayDefaults.closeOnEscape = true;
305302

306-
this.target.opening.pipe(takeUntil(this.destroy$)).subscribe(() => {
307-
if (this.target.tooltipTarget === this) {
308-
document.addEventListener('touchstart', this.onDocumentTouchStart = this.onDocumentTouchStart.bind(this), { passive: true });
309-
}
310-
});
311-
312303
this.target.closing.pipe(takeUntil(this.destroy$)).subscribe((event) => {
313304
if (this.target.tooltipTarget !== this) {
314305
return;
315306
}
316307

317-
document.removeEventListener('touchstart', this.onDocumentTouchStart);
318308
const hidingArgs = { target: this, tooltip: this.target, cancel: false };
319309
this.tooltipHide.emit(hidingArgs);
320310

@@ -323,10 +313,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
323313
}
324314
});
325315

326-
this.target.forceClosed.pipe(takeUntil(this.destroy$)).subscribe(() => {
327-
document.removeEventListener('touchstart', this.onDocumentTouchStart);
328-
});
329-
330316
this.nativeElement.addEventListener('touchstart', this.onTouchStart = this.onTouchStart.bind(this), { passive: true });
331317
}
332318

@@ -336,7 +322,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
336322
public ngOnDestroy() {
337323
this.hideTooltip();
338324
this.nativeElement.removeEventListener('touchstart', this.onTouchStart);
339-
document.removeEventListener('touchstart', this.onDocumentTouchStart);
340325
this.destroy$.next();
341326
this.destroy$.complete();
342327
}

projects/igniteui-angular/src/lib/directives/tooltip/tooltip.directive.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {
2-
Directive, ElementRef, Input, ChangeDetectorRef, Optional, HostBinding, Inject,
3-
Output, EventEmitter
2+
Directive, ElementRef, Input, ChangeDetectorRef, Optional, HostBinding, Inject, OnDestroy
43
} from '@angular/core';
54
import { IgxOverlayService } from '../../services/overlay/overlay';
65
import { OverlaySettings } from '../../services/public_api';
76
import { IgxNavigationService } from '../../core/navigation';
87
import { IgxToggleDirective } from '../toggle/toggle.directive';
8+
import { IgxTooltipTargetDirective } from './tooltip-target.directive';
9+
import { Subject, takeUntil } from 'rxjs';
910

1011
let 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

Comments
 (0)