Skip to content

Commit b1427a8

Browse files
committed
fix(tooltip): match mobile dimensions from spec
Updates the various tooltip dimensions to match [the spec on mobile](https://material.io/guidelines/components/tooltips.html#tooltips-tooltips-mobile). Fixes #9039.
1 parent 3352201 commit b1427a8

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

src/lib/tooltip/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ng_module(
1818
"//src/cdk/keycodes",
1919
"//src/cdk/portal",
2020
"//src/cdk/scrolling",
21+
"//src/cdk/layout",
2122
"@rxjs",
2223
],
2324
tsconfig = ":tsconfig-build.json",

src/lib/tooltip/_tooltip-theme.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
@import '../core/theming/theming';
33
@import '../core/typography/typography-utils';
44

5-
// TODO(crisbeto): these doesn't correspond to any typography levels
6-
// and the width/height appear to be off from the spec.
75
$mat-tooltip-target-height: 22px;
86
$mat-tooltip-font-size: 10px;
97
$mat-tooltip-vertical-padding: ($mat-tooltip-target-height - $mat-tooltip-font-size) / 2;
108

9+
$mat-tooltip-handset-target-height: 32px;
10+
$mat-tooltip-handset-font-size: 14px;
11+
$mat-tooltip-handset-vertical-padding:
12+
($mat-tooltip-handset-target-height - $mat-tooltip-handset-font-size) / 2;
13+
1114
@mixin mat-tooltip-theme($theme) {
1215
.mat-tooltip {
1316
background: mat-color($mat-grey, 700, 0.9);
@@ -21,4 +24,10 @@ $mat-tooltip-vertical-padding: ($mat-tooltip-target-height - $mat-tooltip-font-s
2124
padding-top: $mat-tooltip-vertical-padding;
2225
padding-bottom: $mat-tooltip-vertical-padding;
2326
}
27+
28+
.mat-tooltip-handset {
29+
font-size: $mat-tooltip-handset-font-size;
30+
padding-top: $mat-tooltip-handset-vertical-padding;
31+
padding-bottom: $mat-tooltip-handset-vertical-padding;
32+
}
2433
}

src/lib/tooltip/tooltip-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {PlatformModule} from '@angular/cdk/platform';
1212
import {CommonModule} from '@angular/common';
1313
import {NgModule} from '@angular/core';
1414
import {MatCommonModule} from '@angular/material/core';
15+
import {LayoutModule} from '@angular/cdk/layout';
1516
import {
1617
MAT_TOOLTIP_SCROLL_STRATEGY_PROVIDER,
1718
MAT_TOOLTIP_DEFAULT_OPTIONS,
@@ -27,6 +28,7 @@ import {
2728
MatCommonModule,
2829
PlatformModule,
2930
A11yModule,
31+
LayoutModule,
3032
],
3133
exports: [MatTooltip, TooltipComponent, MatCommonModule],
3234
declarations: [MatTooltip, TooltipComponent],

src/lib/tooltip/tooltip.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="mat-tooltip"
22
[ngClass]="tooltipClass"
3+
[class.mat-tooltip-handset]="(_isHandset | async)!.matches"
34
[style.transform-origin]="_transformOrigin"
45
[@state]="_visibility"
56
(@state.start)="_animationStart()"

src/lib/tooltip/tooltip.scss

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

8+
$mat-tooltip-handset-horizontal-padding: 16px;
9+
$mat-tooltip-handset-margin: 24px;
10+
811
.mat-tooltip-panel {
912
// The overlay reference updates the pointer-events style property directly on the HTMLElement
1013
// depending on the state of the overlay. For tooltips the overlay panel should never enable
@@ -24,3 +27,9 @@ $mat-tooltip-margin: 14px;
2427
outline: solid 1px;
2528
}
2629
}
30+
31+
.mat-tooltip-handset {
32+
margin: $mat-tooltip-handset-margin;
33+
padding-left: $mat-tooltip-handset-horizontal-padding;
34+
padding-right: $mat-tooltip-handset-horizontal-padding;
35+
}

src/lib/tooltip/tooltip.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ describe('MatTooltip', () => {
481481
it('should have consistent right transform origin in any dir', () => {
482482
// Move the button away from the edge of the screen so
483483
// we don't get into the fallback positions.
484-
fixture.componentInstance.button.nativeElement.style.margin = '200px';
484+
fixture.componentInstance.button.nativeElement.style.margin = '300px';
485485

486486
tooltipDirective.position = 'left';
487487
tooltipDirective.show();

src/lib/tooltip/tooltip.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
import {Observable} from 'rxjs/Observable';
4646
import {Subject} from 'rxjs/Subject';
4747
import {matTooltipAnimations} from './tooltip-animations';
48+
import {BreakpointObserver, Breakpoints, BreakpointState} from '@angular/cdk/layout';
4849

4950

5051
export type TooltipPosition = 'left' | 'right' | 'above' | 'below' | 'before' | 'after';
@@ -516,7 +517,12 @@ export class TooltipComponent {
516517
/** Subject for notifying that the tooltip has been hidden from the view */
517518
private readonly _onHide: Subject<any> = new Subject();
518519

519-
constructor(private _changeDetectorRef: ChangeDetectorRef) {}
520+
/** Stream that emits whether the user has a handset-sized display. */
521+
_isHandset: Observable<BreakpointState> = this._breakpointObserver.observe(Breakpoints.Handset);
522+
523+
constructor(
524+
private _changeDetectorRef: ChangeDetectorRef,
525+
private _breakpointObserver: BreakpointObserver) {}
520526

521527
/**
522528
* Shows the tooltip with an animation originating from the provided origin

0 commit comments

Comments
 (0)