Skip to content

Commit d175b01

Browse files
committed
fix(material/tooltip): do not block events to other overlays
Fixes that the tooltip was blocking keyboard events to other overlays, even if it doesn't care about them. Fixes #32760. (cherry picked from commit 06750e0)
1 parent 00806ea commit d175b01

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/material/tooltip/tooltip.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
543543
panelClass: this._overlayPanelClass ? [...this._overlayPanelClass, panelClass] : panelClass,
544544
scrollStrategy: this._injector.get(MAT_TOOLTIP_SCROLL_STRATEGY)(),
545545
disableAnimations: this._animationsDisabled,
546+
eventPredicate: this._overlayEventPredicate,
546547
});
547548

548549
this._updatePosition(this._overlayRef);
@@ -561,11 +562,10 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
561562
.keydownEvents()
562563
.pipe(takeUntil(this._destroyed))
563564
.subscribe(event => {
564-
if (this._isTooltipVisible() && event.keyCode === ESCAPE && !hasModifierKey(event)) {
565-
event.preventDefault();
566-
event.stopPropagation();
567-
this._ngZone.run(() => this.hide(0));
568-
}
565+
// Note: we don't check the `keyCode` since it's covered by the `eventPredicate` above.
566+
event.preventDefault();
567+
event.stopPropagation();
568+
this._ngZone.run(() => this.hide(0));
569569
});
570570

571571
if (this._defaultOptions?.disableTooltipInteractivity) {
@@ -935,6 +935,18 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
935935
);
936936
}
937937
}
938+
939+
/** Determines which events should be routed to the tooltip overlay. */
940+
private _overlayEventPredicate = (event: Event) => {
941+
if (event.type === 'keydown') {
942+
return (
943+
this._isTooltipVisible() &&
944+
(event as KeyboardEvent).keyCode === ESCAPE &&
945+
!hasModifierKey(event as KeyboardEvent)
946+
);
947+
}
948+
return true;
949+
};
938950
}
939951

940952
/**

0 commit comments

Comments
 (0)