Skip to content

Commit 01cbebe

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 1bb8429 commit 01cbebe

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
@@ -627,6 +627,25 @@ describe('MatTooltip', () => {
627627
expect(overlayContainerElement.textContent).toBe('');
628628
}));
629629

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

src/material/tooltip/tooltip.ts

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

0 commit comments

Comments
 (0)