Skip to content

Commit 5f0deba

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

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
@@ -100,8 +100,8 @@ export class CdkStep implements OnChanges {
100100
/** Plain text label of the step. */
101101
@Input() label: string;
102102

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

106106
/** Aria label for the tab. */
107107
@Input('aria-label') ariaLabel: string;
@@ -112,9 +112,6 @@ export class CdkStep implements OnChanges {
112112
*/
113113
@Input('aria-labelledby') ariaLabelledby: string;
114114

115-
/** Alert message when there's an error. */
116-
@Input() alertMessage: string;
117-
118115
/** Whether the user can return to this step once it has been marked as complted. */
119116
@Input()
120117
get editable(): boolean { return this._editable; }
@@ -139,7 +136,16 @@ export class CdkStep implements OnChanges {
139136
}
140137
private _state: StepState | string | null = null;
141138

139+
/** Whether to show the step is in an error state. */
140+
@Input()
141+
get showError(): boolean { return this._showError; }
142+
set showError(value: boolean) {
143+
this._showError = value;
144+
}
145+
private _showError: boolean = false;
146+
142147
/** Whether step is marked as completed. */
148+
@Input()
143149
get completed(): boolean {
144150
return this._customCompleted == null ? this._defaultCompleted() : this._customCompleted;
145151
}
@@ -153,15 +159,16 @@ export class CdkStep implements OnChanges {
153159
}
154160

155161
/** Whether step has error. */
162+
@Input()
156163
get hasError(): boolean {
157-
return this._customError == null ? this._defaultError : this._customError;
164+
return this._customError == null ? this._getDefaultError : this._customError;
158165
}
159166
set hasError(value: boolean) {
160167
this._customError = coerceBooleanProperty(value);
161168
}
162169
private _customError: boolean | null = null;
163170

164-
private get _defaultError() {
171+
private get _getDefaultError() {
165172
return this.stepControl && this.stepControl.invalid;
166173
}
167174

@@ -340,7 +347,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
340347
const step = this._steps.toArray()[index];
341348
const isCurrentStep = this._isCurrentStep(index);
342349

343-
if (step.hasError && !isCurrentStep) {
350+
if (step.showError && step.hasError && !isCurrentStep) {
344351
return STEP_STATE.ERROR;
345352
} else if (step.completed && !isCurrentStep) {
346353
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)