Skip to content

Commit

Permalink
fix(stepper): align appearance with spec
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed Sep 24, 2017
1 parent 3571f68 commit feb5c89
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
17 changes: 16 additions & 1 deletion src/lib/stepper/_stepper-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
$primary: map-get($theme, primary);

.mat-step-header {
&:focus,
&.cdk-keyboard-focused,
&.cdk-program-focused,
&:hover {
background-color: mat-color($background, hover);
}
Expand Down Expand Up @@ -50,4 +51,18 @@
.mat-stepper-vertical, .mat-stepper-horizontal {
font-family: mat-font-family($config);
}

.mat-step-label {
font: {
size: mat-font-size($config, body-1);
weight: mat-font-weight($config, body-1);
};
}

.mat-step-label-selected {
font: {
size: mat-font-size($config, body-2);
weight: mat-font-weight($config, body-2);
};
}
}
4 changes: 3 additions & 1 deletion src/lib/stepper/step-header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div class="mat-step-header-ripple" mat-ripple [matRippleTrigger]="_getHostElement()"></div>
<div [class.mat-step-icon]="icon !== 'number' || selected"
[class.mat-step-icon-not-touched]="icon == 'number' && !selected"
[ngSwitch]="icon">
Expand All @@ -6,7 +7,8 @@
<mat-icon *ngSwitchCase="'done'">done</mat-icon>
</div>
<div class="mat-step-label"
[class.mat-step-label-active]="active">
[class.mat-step-label-active]="active"
[class.mat-step-label-selected]="selected">
<!-- If there is a label template, use it. -->
<ng-container *ngIf="_templateLabel()" [ngTemplateOutlet]="label.template">
</ng-container>
Expand Down
14 changes: 14 additions & 0 deletions src/lib/stepper/step-header.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../core/style/layout-common';

$mat-stepper-label-header-height: 24px !default;
$mat-stepper-label-min-width: 50px !default;
$mat-stepper-side-gap: 24px !default;
Expand All @@ -6,6 +8,13 @@ $mat-stepper-line-gap: 8px !default;
$mat-step-optional-font-size: 12px;
$mat-step-header-icon-size: 16px !default;

.mat-step-header {
overflow: hidden;
outline: none;
cursor: pointer;
position: relative;
}

.mat-step-optional {
font-size: $mat-step-optional-font-size;
}
Expand Down Expand Up @@ -39,3 +48,8 @@ $mat-step-header-icon-size: 16px !default;
text-overflow: ellipsis;
overflow: hidden;
}

.mat-step-header-ripple {
@include mat-fill;
pointer-events: none;
}
21 changes: 19 additions & 2 deletions src/lib/stepper/step-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/

import {FocusMonitor} from '@angular/cdk/a11y';
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
import {Component, Input, ViewEncapsulation} from '@angular/core';
import {Component, Input, ViewEncapsulation, ElementRef, OnDestroy, Renderer2} from '@angular/core';
import {MATERIAL_COMPATIBILITY_MODE} from '@angular/material/core';
import {MdStepLabel} from './step-label';

Expand All @@ -25,7 +26,7 @@ import {MdStepLabel} from './step-label';
preserveWhitespaces: false,
viewProviders: [{provide: MATERIAL_COMPATIBILITY_MODE, useValue: true}],
})
export class MdStepHeader {
export class MdStepHeader implements OnDestroy {
/** Icon for the given step. */
@Input() icon: string;

Expand Down Expand Up @@ -64,6 +65,17 @@ export class MdStepHeader {
}
private _optional: boolean;

constructor(
private _focusMonitor: FocusMonitor,
private _element: ElementRef,
renderer: Renderer2) {
_focusMonitor.monitor(_element.nativeElement, renderer, true);
}

ngOnDestroy() {
this._focusMonitor.stopMonitoring(this._element.nativeElement);
}

/** Returns string label of given step if it is a text label. */
_stringLabel(): string | null {
return this.label instanceof MdStepLabel ? null : this.label;
Expand All @@ -73,4 +85,9 @@ export class MdStepHeader {
_templateLabel(): MdStepLabel | null {
return this.label instanceof MdStepLabel ? this.label : null;
}

/** Returns the host HTML element. */
_getHostElement() {
return this._element.nativeElement;
}
}
7 changes: 5 additions & 2 deletions src/lib/stepper/stepper-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {A11yModule} from '@angular/cdk/a11y';
import {PortalModule} from '@angular/cdk/portal';
import {CdkStepperModule} from '@angular/cdk/stepper';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MdButtonModule} from '@angular/material/button';
import {MdCommonModule} from '@angular/material/core';
import {MdCommonModule, MdRippleModule} from '@angular/material/core';
import {MdIconModule} from '@angular/material/icon';
import {MdStepHeader} from './step-header';
import {MdStepLabel} from './step-label';
Expand All @@ -26,7 +27,9 @@ import {MdStepperNext, MdStepperPrevious} from './stepper-button';
PortalModule,
MdButtonModule,
CdkStepperModule,
MdIconModule
MdIconModule,
A11yModule,
MdRippleModule,
],
exports: [
MdCommonModule,
Expand Down
5 changes: 0 additions & 5 deletions src/lib/stepper/stepper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ $mat-stepper-line-gap: 8px !default;
display: block;
}

.mat-step-header {
overflow: hidden;
outline: none;
}

.mat-horizontal-stepper-header-container {
white-space: nowrap;
display: flex;
Expand Down

0 comments on commit feb5c89

Please sign in to comment.