diff --git a/projects/ion/src/lib/tooltip/tooltip.directive.spec.ts b/projects/ion/src/lib/tooltip/tooltip.directive.spec.ts index 780825313..0ef69d7f4 100644 --- a/projects/ion/src/lib/tooltip/tooltip.directive.spec.ts +++ b/projects/ion/src/lib/tooltip/tooltip.directive.spec.ts @@ -7,6 +7,7 @@ import { TooltipTrigger, } from '../core/types'; import { IonTooltipModule } from './tooltip.module'; +import { IonTooltipDirective } from './tooltip.directive'; @Component({ template: ` @@ -130,6 +131,17 @@ describe('Directive: Tooltip', () => { ); }); + it('should close the tooltip when scrolling the page', async () => { + await sut(); + const directive = IonTooltipDirective.prototype; + jest.spyOn(directive, 'onScroll'); + + fireEvent.mouseEnter(screen.getByTestId('hostTooltip')); + fireEvent.scroll(window); + expect(directive.onScroll).toBeCalled(); + expect(screen.queryByTestId('ion-tooltip')).not.toBeInTheDocument(); + }); + describe('trigger: click', () => { afterEach(async () => { fireEvent.click(screen.getByTestId('hostTooltip')); diff --git a/projects/ion/src/lib/tooltip/tooltip.directive.ts b/projects/ion/src/lib/tooltip/tooltip.directive.ts index 8fcafee40..417a255d1 100644 --- a/projects/ion/src/lib/tooltip/tooltip.directive.ts +++ b/projects/ion/src/lib/tooltip/tooltip.directive.ts @@ -157,6 +157,10 @@ export class IonTooltipDirective implements OnDestroy, OnInit { } } + @HostListener('window:scroll') onScroll(): void { + this.destroyComponent(); + } + ngOnDestroy(): void { this.destroyComponent(); this.subscription$.unsubscribe();