From 28f4f8078afaeb23ca07b6b68b5c287a2a60243b Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 29 Dec 2020 11:03:18 +0200 Subject: [PATCH] fix(material/tooltip): not closing when clicking outside using auxiliary button Similar to #21397. Fixes that the tooltip doesn't close when the user presses outside using the middle or right mouse button. --- src/material/tooltip/tooltip.spec.ts | 19 +++++++++++++++++++ src/material/tooltip/tooltip.ts | 1 + 2 files changed, 20 insertions(+) diff --git a/src/material/tooltip/tooltip.spec.ts b/src/material/tooltip/tooltip.spec.ts index d4e7765c28e1..b5ef3c043d84 100644 --- a/src/material/tooltip/tooltip.spec.ts +++ b/src/material/tooltip/tooltip.spec.ts @@ -627,6 +627,25 @@ describe('MatTooltip', () => { expect(overlayContainerElement.textContent).toBe(''); })); + it('should hide when clicking away with an auxilliary button', fakeAsync(() => { + tooltipDirective.show(); + tick(0); + fixture.detectChanges(); + tick(500); + + expect(tooltipDirective._isTooltipVisible()).toBe(true); + expect(overlayContainerElement.textContent).toContain(initialTooltipMessage); + + dispatchFakeEvent(document.body, 'auxclick'); + tick(0); + fixture.detectChanges(); + tick(500); + fixture.detectChanges(); + + expect(tooltipDirective._isTooltipVisible()).toBe(false); + expect(overlayContainerElement.textContent).toBe(''); + })); + it('should not hide immediately if a click fires while animating', fakeAsync(() => { tooltipDirective.show(); tick(0); diff --git a/src/material/tooltip/tooltip.ts b/src/material/tooltip/tooltip.ts index 28f374f62393..54c26086bbe3 100644 --- a/src/material/tooltip/tooltip.ts +++ b/src/material/tooltip/tooltip.ts @@ -697,6 +697,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit { // won't be rendered if the animations are disabled or there is no web animations polyfill. '[style.zoom]': '_visibility === "visible" ? 1 : null', '(body:click)': 'this._handleBodyInteraction()', + '(body:auxclick)': 'this._handleBodyInteraction()', 'aria-hidden': 'true', } })