Skip to content

Commit c53cc98

Browse files
authored
Merge pull request #16290 from IgniteUI/rivanova/fix-16288-master
fix(tooltip): force close shared tooltip when hovering another target - master
2 parents 7b9c095 + 315baf6 commit c53cc98

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
@@ -3,6 +3,7 @@ import {
33
OnDestroy, inject, DOCUMENT, HostListener,
44
} from '@angular/core';
55
import { IgxOverlayService } from '../../services/overlay/overlay';
6+
import { OverlaySettings } from '../../services/overlay/utilities';
67
import { IgxNavigationService } from '../../core/navigation';
78
import { IgxToggleDirective } from '../toggle/toggle.directive';
89
import { IgxTooltipTargetDirective } from './tooltip-target.directive';
@@ -165,29 +166,43 @@ export class IgxTooltipDirective extends IgxToggleDirective implements OnDestroy
165166

166167
/**
167168
* If there is an animation in progress, this method will reset it to its initial state.
168-
* Optional `force` parameter that ends the animation.
169+
* Allows hovering over the tooltip while an open/close animation is running.
170+
* Stops the animation and immediately shows the tooltip.
169171
*
170172
* @hidden
171-
* @param force if set to `true`, the animation will be ended.
172173
*/
173-
public stopAnimations(force: boolean = false): void {
174+
public stopAnimations(): void {
174175
const info = this.overlayService.getOverlayById(this._overlayId);
175176

176177
if (!info) return;
177178

178179
if (info.openAnimationPlayer) {
179180
info.openAnimationPlayer.reset();
180-
if (force) {
181-
info.openAnimationPlayer.finish();
182-
info.openAnimationPlayer = null;
183-
}
184181
}
185182
if (info.closeAnimationPlayer) {
186183
info.closeAnimationPlayer.reset();
187-
if (force) {
188-
info.closeAnimationPlayer.finish();
189-
info.closeAnimationPlayer = null;
190-
}
184+
}
185+
}
186+
187+
/**
188+
* If there is a close animation in progress, this method will end it.
189+
* If there is no close animation in progress, this method will close the tooltip with no animation.
190+
*
191+
* @param overlaySettings settings to use for closing the tooltip
192+
* @hidden
193+
*/
194+
public forceClose(overlaySettings: OverlaySettings) {
195+
const info = this.overlayService.getOverlayById(this._overlayId);
196+
197+
if (info && info.closeAnimationPlayer) {
198+
info.closeAnimationPlayer.finish();
199+
info.closeAnimationPlayer.reset();
200+
info.closeAnimationPlayer = null;
201+
} else if (!this.collapsed) {
202+
const animation = overlaySettings.positionStrategy.settings.closeAnimation;
203+
overlaySettings.positionStrategy.settings.closeAnimation = null;
204+
this.close();
205+
overlaySettings.positionStrategy.settings.closeAnimation = animation;
191206
}
192207
}
193208

0 commit comments

Comments
 (0)