Skip to content

Commit 27bb590

Browse files
crisbetommalerba
authored andcommitted
fix(material/tooltip): not closing when clicking outside using auxiliary button (#21467)
Similar to #21397. Fixes that the tooltip doesn't close when the user presses outside using the middle or right mouse button. (cherry picked from commit ddf99cb)
1 parent 2bad02f commit 27bb590

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/material/tooltip/tooltip.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,25 @@ describe('MatTooltip', () => {
628628
expect(overlayContainerElement.textContent).toBe('');
629629
}));
630630

631+
it('should hide when clicking away with an auxilliary button', fakeAsync(() => {
632+
tooltipDirective.show();
633+
tick(0);
634+
fixture.detectChanges();
635+
tick(500);
636+
637+
expect(tooltipDirective._isTooltipVisible()).toBe(true);
638+
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);
639+
640+
dispatchFakeEvent(document.body, 'auxclick');
641+
tick(0);
642+
fixture.detectChanges();
643+
tick(500);
644+
fixture.detectChanges();
645+
646+
expect(tooltipDirective._isTooltipVisible()).toBe(false);
647+
expect(overlayContainerElement.textContent).toBe('');
648+
}));
649+
631650
it('should not hide immediately if a click fires while animating', fakeAsync(() => {
632651
tooltipDirective.show();
633652
tick(0);

src/material/tooltip/tooltip.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
666666
// won't be rendered if the animations are disabled or there is no web animations polyfill.
667667
'[style.zoom]': '_visibility === "visible" ? 1 : null',
668668
'(body:click)': 'this._handleBodyInteraction()',
669+
'(body:auxclick)': 'this._handleBodyInteraction()',
669670
'aria-hidden': 'true',
670671
}
671672
})

0 commit comments

Comments
 (0)