Skip to content

Commit d04230c

Browse files
devversionjelbourn
authored andcommitted
fix(tooltip): panel element blocks hover effects (#5514)
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 a394418 commit d04230c

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ import {
1212
ViewChild,
1313
ChangeDetectionStrategy
1414
} from '@angular/core';
15+
import {
16+
TooltipPosition,
17+
MdTooltip,
18+
MdTooltipModule,
19+
SCROLL_THROTTLE_MS,
20+
TOOLTIP_PANEL_CLASS
21+
} from './index';
1522
import {AnimationEvent} from '@angular/animations';
1623
import {By} from '@angular/platform-browser';
1724
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
18-
import {TooltipPosition, MdTooltip, MdTooltipModule, SCROLL_THROTTLE_MS} from './index';
1925
import {Directionality, Direction} from '../core/bidi/index';
2026
import {OverlayModule, Scrollable, OverlayContainer} from '../core/overlay/index';
2127
import {Platform} from '../core/platform/platform';
2228
import {dispatchFakeEvent} from '@angular/cdk/testing';
2329

24-
2530
const initialTooltipMessage = 'initial tooltip message';
2631

2732
describe('MdTooltip', () => {
@@ -115,6 +120,18 @@ describe('MdTooltip', () => {
115120
expect(overlayContainerElement.textContent).toContain(initialTooltipMessage);
116121
}));
117122

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

src/lib/tooltip/tooltip.ts

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

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

276279
config.direction = this._dir ? this._dir.value : 'ltr';
277280
config.positionStrategy = strategy;
281+
config.panelClass = TOOLTIP_PANEL_CLASS;
278282
config.scrollStrategy = this._overlay.scrollStrategies.reposition({
279283
scrollThrottle: SCROLL_THROTTLE_MS
280284
});

0 commit comments

Comments
 (0)