Skip to content

Commit 525cdb9

Browse files
Merge pull request #16291 from IgniteUI/rivanova/fix-16288-20.1.x
fix(tooltip): force close shared tooltip when hovering another target - 20.1.x
2 parents 3e0985a + 9618430 commit 525cdb9

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
559559

560560
/**
561561
* Used when a single tooltip is used for multiple targets.
562-
* If the tooltip is shown for one target and the user interacts with another target,
563-
* the tooltip is instantly hidden for the first target.
564562
*/
565563
private _checkTooltipForMultipleTargets(): void {
566564
if (!this.target.tooltipTarget) {
@@ -573,8 +571,10 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
573571
this.target.tooltipTarget._removeCloseButtonFromTooltip();
574572
}
575573

574+
// If the tooltip is shown for one target and the user interacts with another target,
575+
// the tooltip is instantly hidden for the first target.
576576
clearTimeout(this.target.timeoutId);
577-
this.target.stopAnimations(true);
577+
this.target.forceClose(this._mergedOverlaySettings);
578578

579579
this.target.tooltipTarget = this;
580580
this._isForceClosed = true;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,31 @@ describe('IgxTooltip', () => {
558558
flush();
559559
}));
560560

561+
it('Should position relative to its target when having no close animation - #16288', fakeAsync(() => {
562+
targetOne.positionSettings = targetTwo.positionSettings = {
563+
openAnimation: undefined,
564+
closeAnimation: undefined
565+
};
566+
fix.detectChanges();
567+
568+
hoverElement(buttonOne);
569+
tick(targetOne.showDelay);
570+
571+
verifyTooltipVisibility(tooltipNativeElement, targetOne, true);
572+
verifyTooltipPosition(tooltipNativeElement, buttonOne, true);
573+
574+
unhoverElement(buttonOne);
575+
576+
hoverElement(buttonTwo);
577+
tick(targetTwo.showDelay);
578+
579+
// Tooltip is visible and positioned relative to buttonTwo
580+
verifyTooltipVisibility(tooltipNativeElement, targetTwo, true);
581+
verifyTooltipPosition(tooltipNativeElement, buttonTwo);
582+
// Tooltip is NOT visible and positioned relative to buttonOne
583+
verifyTooltipPosition(tooltipNativeElement, buttonOne, false);
584+
}));
585+
561586
it('Hovering first target briefly and then hovering second target leads to tooltip showing for second target', fakeAsync(() => {
562587
targetOne.showDelay = 600;
563588
fix.detectChanges();

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
AfterViewInit,
66
} from '@angular/core';
77
import { IgxOverlayService } from '../../services/overlay/overlay';
8+
import { OverlaySettings } from '../../services/overlay/utilities';
89
import { IgxNavigationService } from '../../core/navigation';
910
import { IgxToggleDirective } from '../toggle/toggle.directive';
1011
import { IgxTooltipTargetDirective } from './tooltip-target.directive';
@@ -178,29 +179,43 @@ export class IgxTooltipDirective extends IgxToggleDirective implements AfterView
178179

179180
/**
180181
* If there is an animation in progress, this method will reset it to its initial state.
181-
* Optional `force` parameter that ends the animation.
182+
* Allows hovering over the tooltip while an open/close animation is running.
183+
* Stops the animation and immediately shows the tooltip.
182184
*
183185
* @hidden
184-
* @param force if set to `true`, the animation will be ended.
185186
*/
186-
public stopAnimations(force: boolean = false): void {
187+
public stopAnimations(): void {
187188
const info = this.overlayService.getOverlayById(this._overlayId);
188189

189190
if (!info) return;
190191

191192
if (info.openAnimationPlayer) {
192193
info.openAnimationPlayer.reset();
193-
if (force) {
194-
info.openAnimationPlayer.finish();
195-
info.openAnimationPlayer = null;
196-
}
197194
}
198195
if (info.closeAnimationPlayer) {
199196
info.closeAnimationPlayer.reset();
200-
if (force) {
201-
info.closeAnimationPlayer.finish();
202-
info.closeAnimationPlayer = null;
203-
}
197+
}
198+
}
199+
200+
/**
201+
* If there is a close animation in progress, this method will end it.
202+
* If there is no close animation in progress, this method will close the tooltip with no animation.
203+
*
204+
* @param overlaySettings settings to use for closing the tooltip
205+
* @hidden
206+
*/
207+
public forceClose(overlaySettings: OverlaySettings) {
208+
const info = this.overlayService.getOverlayById(this._overlayId);
209+
210+
if (info && info.closeAnimationPlayer) {
211+
info.closeAnimationPlayer.finish();
212+
info.closeAnimationPlayer.reset();
213+
info.closeAnimationPlayer = null;
214+
} else if (!this.collapsed) {
215+
const animation = overlaySettings.positionStrategy.settings.closeAnimation;
216+
overlaySettings.positionStrategy.settings.closeAnimation = null;
217+
this.close();
218+
overlaySettings.positionStrategy.settings.closeAnimation = animation;
204219
}
205220
}
206221

0 commit comments

Comments
 (0)