Skip to content

Commit dd56ac7

Browse files
committed
feat(stepper): add showError Input, update _getIndicatorType logic, add completed and hasError as an Input, rename alertMessage to errorMessage
1 parent 7973e5f commit dd56ac7

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

src/cdk/stepper/stepper.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export class CdkStep implements OnChanges {
9898
/** Plain text label of the step. */
9999
@Input() label: string;
100100

101-
/** Alert message when there's an error. */
102-
@Input() alertMessage: string;
101+
/** Error message to display when there's an error. */
102+
@Input() errorMessage: string;
103103

104104
/** Aria label for the tab. */
105105
@Input('aria-label') ariaLabel: string;
@@ -110,9 +110,6 @@ export class CdkStep implements OnChanges {
110110
*/
111111
@Input('aria-labelledby') ariaLabelledby: string;
112112

113-
/** Alert message when there's an error. */
114-
@Input() alertMessage: string;
115-
116113
/** Whether the user can return to this step once it has been marked as complted. */
117114
@Input()
118115
get editable(): boolean { return this._editable; }
@@ -137,7 +134,16 @@ export class CdkStep implements OnChanges {
137134
}
138135
private _state: StepState | string | null = null;
139136

137+
/** Whether to show the step is in an error state. */
138+
@Input()
139+
get showError(): boolean { return this._showError; }
140+
set showError(value: boolean) {
141+
this._showError = value;
142+
}
143+
private _showError: boolean = false;
144+
140145
/** Whether step is marked as completed. */
146+
@Input()
141147
get completed(): boolean {
142148
return this._customCompleted == null ? this._defaultCompleted : this._customCompleted;
143149
}
@@ -151,15 +157,16 @@ export class CdkStep implements OnChanges {
151157
}
152158

153159
/** Whether step has error. */
160+
@Input()
154161
get hasError(): boolean {
155-
return this._customError == null ? this._defaultError : this._customError;
162+
return this._customError == null ? this._getDefaultError : this._customError;
156163
}
157164
set hasError(value: boolean) {
158165
this._customError = coerceBooleanProperty(value);
159166
}
160167
private _customError: boolean | null = null;
161168

162-
private get _defaultError() {
169+
private get _getDefaultError() {
163170
return this.stepControl && this.stepControl.invalid;
164171
}
165172

@@ -328,7 +335,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
328335
const step = this._steps.toArray()[index];
329336
const isCurrentStep = this._isCurrentStep(index);
330337

331-
if (step.hasError && !isCurrentStep) {
338+
if (step.showError && step.hasError && !isCurrentStep) {
332339
return STEP_STATE.ERROR;
333340
} else if (step.completed && !isCurrentStep) {
334341
return STEP_STATE.DONE;

src/demo-app/stepper/stepper-demo.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ <h3>Linear Vertical Stepper Demo using a single form</h3>
66
<mat-step
77
formGroupName="0"
88
[stepControl]="formArray?.get([0])"
9-
alertMessage="Some fields are required"
9+
errorMessage="Some fields are required"
10+
[completed]="true"
1011
>
1112
<ng-template matStepLabel>Fill out your name</ng-template>
1213
<mat-form-field>
@@ -29,7 +30,8 @@ <h3>Linear Vertical Stepper Demo using a single form</h3>
2930
formGroupName="1"
3031
[stepControl]="formArray?.get([1])"
3132
optional
32-
alertMessage="The input is invalid"
33+
errorMessage="The input is invalid"
34+
[showError]="true"
3335
>
3436
<ng-template matStepLabel>
3537
<div>Fill out your email address</div>
@@ -107,7 +109,7 @@ <h3>Linear Horizontal Stepper Demo using a different form for each step</h3>
107109
<h3>Vertical Stepper Demo</h3>
108110
<mat-checkbox [(ngModel)]="isNonEditable">Make steps non-editable</mat-checkbox>
109111
<mat-vertical-stepper>
110-
<mat-step [editable]="!isNonEditable">
112+
<mat-step [editable]="!isNonEditable" [completed]="false">
111113
<ng-template matStepLabel>Fill out your name</ng-template>
112114
<mat-form-field>
113115
<mat-label>First name</mat-label>
@@ -123,7 +125,7 @@ <h3>Vertical Stepper Demo</h3>
123125
</div>
124126
</mat-step>
125127

126-
<mat-step [editable]="!isNonEditable">
128+
<mat-step [editable]="!isNonEditable" [completed]="false">
127129
<ng-template matStepLabel>
128130
<div>Fill out your phone number</div>
129131
</ng-template>
@@ -137,7 +139,7 @@ <h3>Vertical Stepper Demo</h3>
137139
</div>
138140
</mat-step>
139141

140-
<mat-step [editable]="!isNonEditable">
142+
<mat-step [editable]="!isNonEditable" [completed]="false">
141143
<ng-template matStepLabel>
142144
<div>Fill out your address</div>
143145
</ng-template>
@@ -151,7 +153,7 @@ <h3>Vertical Stepper Demo</h3>
151153
</div>
152154
</mat-step>
153155

154-
<mat-step>
156+
<mat-step [editable]="!isNonEditable" [completed]="false">
155157
<ng-template matStepLabel>Confirm your information</ng-template>
156158
Everything seems correct.
157159
<div>

src/lib/stepper/step-header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
<div class="mat-step-text-label" *ngIf="_stringLabel()">{{label}}</div>
5858

5959
<div class="mat-step-optional" *ngIf="optional && state != 'error'">{{_intl.optionalLabel}}</div>
60-
<div class="mat-step-sub-label-error" *ngIf="state == 'error'">{{alertMessage}}</div>
60+
<div class="mat-step-sub-label-error" *ngIf="state == 'error'">{{errorMessage}}</div>
6161
</div>
6262

src/lib/stepper/step-header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class MatStepHeader implements OnDestroy {
4444
/** Label of the given step. */
4545
@Input() label: MatStepLabel | string;
4646

47-
/** Alert message when there's an error. */
48-
@Input() alertMessage: string;
47+
/** Error message to display when there's an error. */
48+
@Input() errorMessage: string;
4949

5050
/** Overrides for the header icons, passed in via the stepper. */
5151
@Input() iconOverrides: {[key: string]: TemplateRef<MatStepperIconContext>};

src/lib/stepper/stepper-horizontal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[selected]="selectedIndex === i"
1818
[active]="step.completed || selectedIndex === i || !linear"
1919
[optional]="step.optional"
20-
[alertMessage]="step.alertMessage"
20+
[errorMessage]="step.errorMessage"
2121
[iconOverrides]="_iconOverrides">
2222
</mat-step-header>
2323
<div *ngIf="!isLast" class="mat-stepper-horizontal-line"></div>

src/lib/stepper/stepper-vertical.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[selected]="selectedIndex === i"
1717
[active]="step.completed || selectedIndex === i || !linear"
1818
[optional]="step.optional"
19-
[alertMessage]="step.alertMessage"
19+
[errorMessage]="step.errorMessage"
2020
[iconOverrides]="_iconOverrides">
2121
</mat-step-header>
2222

0 commit comments

Comments
 (0)