Skip to content

Commit e647bf8

Browse files
committed
fix(tooltip): add check for multiple targets
1 parent a0434de commit e647bf8

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
277277

278278
private _destroy$ = new Subject<void>();
279279
private _autoHideDelay = 180;
280+
private _isForceClosed = false;
280281

281282
constructor(private _element: ElementRef,
282283
@Optional() private _navigationService: IgxNavigationService, private _viewContainerRef: ViewContainerRef) {
@@ -303,6 +304,7 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
303304
}
304305

305306
this._checkOutletAndOutsideClick();
307+
this._checkTooltipForMultipleTargets();
306308
this._showOnInteraction();
307309
}
308310

@@ -311,10 +313,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
311313
*/
312314
@HostListener('mouseleave')
313315
public onMouseLeave() {
314-
if (this.sticky) {
315-
return;
316-
}
317-
318316
if (this.tooltipDisabled) {
319317
return;
320318
}
@@ -433,10 +431,14 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
433431
}
434432

435433
private _showTooltip(withDelay: boolean, withEvents: boolean): void {
436-
if (!this.target.collapsed) {
434+
if (!this.target.collapsed && !this._isForceClosed) {
437435
return;
438436
}
439437

438+
if (this._isForceClosed) {
439+
this._isForceClosed = false;
440+
}
441+
440442
if (withEvents) {
441443
const showingArgs = { target: this, tooltip: this.target, cancel: false };
442444
this.tooltipShow.emit(showingArgs);
@@ -457,7 +459,7 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
457459
}
458460

459461
private _hideOnInteraction(): void {
460-
if (!this.target.sticky) {
462+
if (!this.sticky) {
461463
this._setAutoHide();
462464
}
463465
}
@@ -470,8 +472,31 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
470472
}, this._autoHideDelay);
471473
}
472474

475+
/**
476+
* Used when the browser animations are set to a lower percentage
477+
* and the user interacts with the target or tooltip __while__ an animation is playing.
478+
* It stops the running animation, and the tooltip is instantly shown.
479+
*/
473480
private _stopTimeoutAndAnimation(): void {
474481
clearTimeout(this.target.timeoutId);
475482
this.target.stopAnimations();
476483
}
484+
485+
/**
486+
* Used when a single tooltip is used for multiple targets.
487+
* If the tooltip is shown for one target and the user interacts with another target,
488+
* the tooltip is instantly hidden for the first target.
489+
*/
490+
private _checkTooltipForMultipleTargets(): void {
491+
if (!this.target.tooltipTarget) {
492+
this.target.tooltipTarget = this;
493+
}
494+
495+
if (this.target.tooltipTarget !== this) {
496+
clearTimeout(this.target.timeoutId);
497+
this.target.stopAnimations(true);
498+
this.target.tooltipTarget = this;
499+
this._isForceClosed = true;
500+
}
501+
}
477502
}

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ export class IgxTooltipDirective extends IgxToggleDirective implements OnInit, O
7272
@Input()
7373
public context;
7474

75-
76-
/**
77-
* Specifies if the tooltip remains visible until the user closes it via the close button or Esc key.
78-
*/
79-
@Input()
80-
public sticky = false;
81-
8275
/**
8376
* Identifier for the tooltip.
8477
* If this is property is not explicitly set, it will be automatically generated.
@@ -110,15 +103,8 @@ export class IgxTooltipDirective extends IgxToggleDirective implements OnInit, O
110103

111104
/**
112105
* @hidden
113-
* Returns whether close time out has started
114106
*/
115-
public toBeHidden = false;
116-
117-
/**
118-
* @hidden
119-
* Returns whether open time out has started
120-
*/
121-
public toBeShown = false;
107+
public tooltipTarget;
122108

123109
/**
124110
* @hidden
@@ -181,16 +167,31 @@ export class IgxTooltipDirective extends IgxToggleDirective implements OnInit, O
181167
this.onHide();
182168
}
183169

184-
protected stopAnimations() {
170+
/**
171+
* If there is an animation in progress, this method will reset it to its initial state.
172+
* Optional `force` parameter that ends the animation.
173+
*
174+
* @hidden
175+
* @param force if set to `true`, the animation will be ended.
176+
*/
177+
protected stopAnimations(force: boolean = false) {
185178
const info = this.overlayService.getOverlayById(this._overlayId);
186179

187180
if (!info) return;
188181

189182
if (info.openAnimationPlayer) {
190183
info.openAnimationPlayer.reset();
184+
if (force) {
185+
info.openAnimationPlayer.finish();
186+
info.openAnimationPlayer = null;
187+
}
191188
}
192189
if (info.closeAnimationPlayer) {
193190
info.closeAnimationPlayer.reset();
191+
if (force) {
192+
info.closeAnimationPlayer.finish();
193+
info.closeAnimationPlayer = null;
194+
}
194195
}
195196
}
196197

0 commit comments

Comments
 (0)