Skip to content

Commit 4122ae2

Browse files
crisbetoandrewseguin
authored andcommitted
fix(stepper): align appearance with spec (#7279)
Aligns the stepper appearance closer to the spec by: * Removing the focused background when focused by mouse. Now it only shows up for programmatic and keyboard focus. * Adding ripples to the step header. * Using a slightly heavier font font the active step. * Using `cursor: pointer` to show that the step is clickable. Fixes #7260.
1 parent d9ba13f commit 4122ae2

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

src/lib/stepper/_stepper-theme.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
$primary: map-get($theme, primary);
99

1010
.mat-step-header {
11-
&:focus,
11+
&.cdk-keyboard-focused,
12+
&.cdk-program-focused,
1213
&:hover {
1314
background-color: mat-color($background, hover);
1415
}
@@ -50,4 +51,18 @@
5051
.mat-stepper-vertical, .mat-stepper-horizontal {
5152
font-family: mat-font-family($config);
5253
}
54+
55+
.mat-step-label {
56+
font: {
57+
size: mat-font-size($config, body-1);
58+
weight: mat-font-weight($config, body-1);
59+
};
60+
}
61+
62+
.mat-step-label-selected {
63+
font: {
64+
size: mat-font-size($config, body-2);
65+
weight: mat-font-weight($config, body-2);
66+
};
67+
}
5368
}

src/lib/stepper/step-header.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<div class="mat-step-header-ripple" mat-ripple [matRippleTrigger]="_getHostElement()"></div>
12
<div [class.mat-step-icon]="icon !== 'number' || selected"
23
[class.mat-step-icon-not-touched]="icon == 'number' && !selected"
34
[ngSwitch]="icon">
@@ -6,7 +7,8 @@
67
<mat-icon *ngSwitchCase="'done'">done</mat-icon>
78
</div>
89
<div class="mat-step-label"
9-
[class.mat-step-label-active]="active">
10+
[class.mat-step-label-active]="active"
11+
[class.mat-step-label-selected]="selected">
1012
<!-- If there is a label template, use it. -->
1113
<ng-container *ngIf="_templateLabel()" [ngTemplateOutlet]="label.template">
1214
</ng-container>

src/lib/stepper/step-header.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import '../core/style/layout-common';
2+
13
$mat-stepper-label-header-height: 24px !default;
24
$mat-stepper-label-min-width: 50px !default;
35
$mat-stepper-side-gap: 24px !default;
@@ -6,6 +8,13 @@ $mat-stepper-line-gap: 8px !default;
68
$mat-step-optional-font-size: 12px;
79
$mat-step-header-icon-size: 16px !default;
810

11+
.mat-step-header {
12+
overflow: hidden;
13+
outline: none;
14+
cursor: pointer;
15+
position: relative;
16+
}
17+
918
.mat-step-optional {
1019
font-size: $mat-step-optional-font-size;
1120
}
@@ -39,3 +48,8 @@ $mat-step-header-icon-size: 16px !default;
3948
text-overflow: ellipsis;
4049
overflow: hidden;
4150
}
51+
52+
.mat-step-header-ripple {
53+
@include mat-fill;
54+
pointer-events: none;
55+
}

src/lib/stepper/step-header.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {FocusMonitor} from '@angular/cdk/a11y';
910
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
10-
import {Component, Input, ViewEncapsulation} from '@angular/core';
11+
import {Component, Input, ViewEncapsulation, ElementRef, OnDestroy, Renderer2} from '@angular/core';
12+
import {MATERIAL_COMPATIBILITY_MODE} from '@angular/material/core';
1113
import {MatStepLabel} from './step-label';
1214

1315

@@ -23,7 +25,7 @@ import {MatStepLabel} from './step-label';
2325
encapsulation: ViewEncapsulation.None,
2426
preserveWhitespaces: false,
2527
})
26-
export class MatStepHeader {
28+
export class MatStepHeader implements OnDestroy {
2729
/** Icon for the given step. */
2830
@Input() icon: string;
2931

@@ -62,6 +64,17 @@ export class MatStepHeader {
6264
}
6365
private _optional: boolean;
6466

67+
constructor(
68+
private _focusMonitor: FocusMonitor,
69+
private _element: ElementRef,
70+
renderer: Renderer2) {
71+
_focusMonitor.monitor(_element.nativeElement, renderer, true);
72+
}
73+
74+
ngOnDestroy() {
75+
this._focusMonitor.stopMonitoring(this._element.nativeElement);
76+
}
77+
6578
/** Returns string label of given step if it is a text label. */
6679
_stringLabel(): string | null {
6780
return this.label instanceof MatStepLabel ? null : this.label;
@@ -71,4 +84,9 @@ export class MatStepHeader {
7184
_templateLabel(): MatStepLabel | null {
7285
return this.label instanceof MatStepLabel ? this.label : null;
7386
}
87+
88+
/** Returns the host HTML element. */
89+
_getHostElement() {
90+
return this._element.nativeElement;
91+
}
7492
}

src/lib/stepper/stepper-module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {A11yModule} from '@angular/cdk/a11y';
910
import {PortalModule} from '@angular/cdk/portal';
1011
import {CdkStepperModule} from '@angular/cdk/stepper';
1112
import {CommonModule} from '@angular/common';
1213
import {NgModule} from '@angular/core';
1314
import {MatButtonModule} from '@angular/material/button';
14-
import {MatCommonModule} from '@angular/material/core';
15+
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1516
import {MatIconModule} from '@angular/material/icon';
1617
import {MatStepHeader} from './step-header';
1718
import {MatStepLabel} from './step-label';
@@ -26,7 +27,9 @@ import {MatStepperNext, MatStepperPrevious} from './stepper-button';
2627
PortalModule,
2728
MatButtonModule,
2829
CdkStepperModule,
29-
MatIconModule
30+
MatIconModule,
31+
A11yModule,
32+
MatRippleModule,
3033
],
3134
exports: [
3235
MatCommonModule,

src/lib/stepper/stepper.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ $mat-stepper-line-gap: 8px !default;
1212
display: block;
1313
}
1414

15-
.mat-step-header {
16-
overflow: hidden;
17-
outline: none;
18-
}
19-
2015
.mat-horizontal-stepper-header-container {
2116
white-space: nowrap;
2217
display: flex;

0 commit comments

Comments
 (0)