Skip to content

Commit 1ab727b

Browse files
committed
fix(tooltip): panel element blocks hover effects
By default the overlay container always has pointer events disabled. Currently the tooltip component also has pointer events disabled. The only thing that has pointer events enabled is the overlay panel element. This can be problematic because as soon as someone hovers of the overlay panel element, the pointer events & hover effects are going to the overlay panel element instead of the element that the tooltip just overlays. Fixes #4691
1 parent b00f838 commit 1ab727b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/lib/tooltip/tooltip.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ $mat-tooltip-horizontal-padding: 8px;
55
$mat-tooltip-max-width: 250px;
66
$mat-tooltip-margin: 14px;
77

8-
:host {
9-
pointer-events: none;
8+
.mat-tooltip-panel {
9+
// The overlay reference updates the pointer-events style property directly on the HTMLElement
10+
// depending on the state of the overlay. For tooltips the overlay panel should never enable
11+
// pointer events. To overwrite the inline CSS from the overlay reference `!important` is needed.
12+
pointer-events: none !important;
1013
}
1114

1215
.mat-tooltip {

src/lib/tooltip/tooltip.spec.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import {
1515
import {AnimationEvent} from '@angular/animations';
1616
import {By} from '@angular/platform-browser';
1717
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
18-
import {TooltipPosition, MdTooltip, MdTooltipModule, SCROLL_THROTTLE_MS} from './index';
1918
import {Directionality, Direction} from '../core/bidi/index';
2019
import {OverlayModule, Scrollable, OverlayContainer} from '../core/overlay/index';
2120
import {Platform} from '../core/platform/platform';
2221
import {dispatchFakeEvent} from '../core/testing/dispatch-events';
23-
22+
import {
23+
TooltipPosition, MdTooltip, MdTooltipModule, SCROLL_THROTTLE_MS, TOOLTIP_PANEL_CLASS
24+
} from './index';
2425

2526
const initialTooltipMessage = 'initial tooltip message';
2627

@@ -115,6 +116,18 @@ describe('MdTooltip', () => {
115116
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);
116117
}));
117118

119+
it('should set a css class on the overlay panel element', fakeAsync(() => {
120+
tooltipDirective.show();
121+
fixture.detectChanges();
122+
tick(0);
123+
124+
const overlayRef = tooltipDirective._overlayRef;
125+
126+
expect(overlayRef).not.toBeNull();
127+
expect(overlayRef!.overlayElement.classList).toContain(TOOLTIP_PANEL_CLASS,
128+
'Expected the overlay panel element to have the tooltip panel class set.');
129+
}));
130+
118131
it('should not show if disabled', fakeAsync(() => {
119132
// Test that disabling the tooltip will not set the tooltip visible
120133
tooltipDirective.disabled = true;

src/lib/tooltip/tooltip.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export const TOUCHEND_HIDE_DELAY = 1500;
5151
/** Time in ms to throttle repositioning after scroll events. */
5252
export const SCROLL_THROTTLE_MS = 20;
5353

54+
/** CSS class that will be attached to the overlay panel. */
55+
export const TOOLTIP_PANEL_CLASS = 'mat-tooltip-panel';
56+
5457
/** Creates an error to be thrown if the user supplied an invalid tooltip position. */
5558
export function getMdTooltipInvalidPositionError(position: string) {
5659
return Error(`Tooltip position "${position}" is invalid.`);
@@ -264,6 +267,7 @@ export class MdTooltip implements OnDestroy {
264267

265268
config.direction = this._dir ? this._dir.value : 'ltr';
266269
config.positionStrategy = strategy;
270+
config.panelClass = TOOLTIP_PANEL_CLASS;
267271
config.scrollStrategy = this._overlay.scrollStrategies.reposition({
268272
scrollThrottle: SCROLL_THROTTLE_MS
269273
});

0 commit comments

Comments
 (0)