Skip to content

Commit 925342c

Browse files
committed
docs(material/stepper): add example with MatStepperIntl service
1 parent 5832463 commit 925342c

File tree

6 files changed

+131
-1
lines changed

6 files changed

+131
-1
lines changed

src/components-examples/material/stepper/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ng_module(
2121
"//src/material/button",
2222
"//src/material/icon",
2323
"//src/material/input",
24+
"//src/material/radio",
2425
"//src/material/stepper",
2526
"//src/material/stepper/testing",
2627
"@npm//@angular/common",

src/components-examples/material/stepper/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {NgModule} from '@angular/core';
2-
import {ReactiveFormsModule} from '@angular/forms';
2+
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
33
import {CommonModule} from '@angular/common';
44
import {MatButtonModule} from '@angular/material/button';
55
import {MatIconModule} from '@angular/material/icon';
66
import {MatInputModule} from '@angular/material/input';
7+
import {MatRadioModule} from '@angular/material/radio';
78
import {MatStepperModule} from '@angular/material/stepper';
89
import {StepperEditableExample} from './stepper-editable/stepper-editable-example';
910
import {StepperErrorsExample} from './stepper-errors/stepper-errors-example';
@@ -15,13 +16,15 @@ import {StepperOverviewExample} from './stepper-overview/stepper-overview-exampl
1516
import {StepperStatesExample} from './stepper-states/stepper-states-example';
1617
import {StepperVerticalExample} from './stepper-vertical/stepper-vertical-example';
1718
import {StepperHarnessExample} from './stepper-harness/stepper-harness-example';
19+
import {StepperIntlExample} from './stepper-intl/stepper-intl-example';
1820
import {StepperLazyContentExample} from './stepper-lazy-content/stepper-lazy-content-example';
1921
import {StepperResponsiveExample} from './stepper-responsive/stepper-responsive-example';
2022

2123
export {
2224
StepperEditableExample,
2325
StepperErrorsExample,
2426
StepperHarnessExample,
27+
StepperIntlExample,
2528
StepperLabelPositionBottomExample,
2629
StepperOptionalExample,
2730
StepperOverviewExample,
@@ -35,6 +38,7 @@ const EXAMPLES = [
3538
StepperEditableExample,
3639
StepperErrorsExample,
3740
StepperHarnessExample,
41+
StepperIntlExample,
3842
StepperLabelPositionBottomExample,
3943
StepperOptionalExample,
4044
StepperOverviewExample,
@@ -46,9 +50,11 @@ const EXAMPLES = [
4650

4751
@NgModule({
4852
imports: [
53+
FormsModule,
4954
MatButtonModule,
5055
MatIconModule,
5156
MatInputModule,
57+
MatRadioModule,
5258
MatStepperModule,
5359
ReactiveFormsModule,
5460
CommonModule,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.mat-stepper-horizontal {
2+
margin-top: 8px;
3+
}
4+
5+
.mat-form-field {
6+
margin-top: 16px;
7+
}
8+
9+
.mat-radio-group {
10+
display: flex;
11+
flex-direction: column;
12+
margin: 15px 0;
13+
}
14+
15+
.mat-radio-button {
16+
margin: 5px;
17+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<label>Pick the text for the optional label</label>
2+
<mat-radio-group
3+
aria-label="Select an option for the optional label"
4+
[(ngModel)]="optionalLabelText"
5+
(ngModelChange)="updateOptionalLabel()"
6+
>
7+
<mat-radio-button
8+
*ngFor="let optionalLabelTextChoice of optionalLabelTextChoices"
9+
[value]="optionalLabelTextChoice"
10+
>
11+
{{optionalLabelTextChoice}}
12+
</mat-radio-button>
13+
</mat-radio-group>
14+
<mat-horizontal-stepper #stepper>
15+
<mat-step [stepControl]="firstFormGroup">
16+
<form [formGroup]="firstFormGroup">
17+
<ng-template matStepLabel>Fill out your name</ng-template>
18+
<mat-form-field>
19+
<mat-label>Name</mat-label>
20+
<input
21+
matInput
22+
placeholder="Last name, First name"
23+
formControlName="firstCtrl"
24+
required
25+
/>
26+
</mat-form-field>
27+
<div>
28+
<button mat-button matStepperNext>Next</button>
29+
</div>
30+
</form>
31+
</mat-step>
32+
<mat-step
33+
[stepControl]="secondFormGroup"
34+
label="Fill out your address"
35+
optional
36+
>
37+
<form [formGroup]="secondFormGroup">
38+
<mat-form-field>
39+
<mat-label>Address</mat-label>
40+
<input
41+
matInput
42+
formControlName="secondCtrl"
43+
placeholder="Ex. 1 Main St, New York, NY"
44+
/>
45+
</mat-form-field>
46+
<div>
47+
<button mat-button matStepperPrevious>Back</button>
48+
<button mat-button matStepperNext>Next</button>
49+
</div>
50+
</form>
51+
</mat-step>
52+
<mat-step>
53+
<ng-template matStepLabel>Done</ng-template>
54+
<p>You are now done.</p>
55+
<div>
56+
<button mat-button matStepperPrevious>Back</button>
57+
<button mat-button (click)="stepper.reset()">Reset</button>
58+
</div>
59+
</mat-step>
60+
</mat-horizontal-stepper>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
import {MatStepperIntl} from '@angular/material/stepper';
4+
5+
export class StepperIntl extends MatStepperIntl {
6+
// the default optional label text, if unspecified is "Optional"
7+
optionalLabel = 'Optional Label';
8+
}
9+
10+
/**
11+
* @title Stepper that uses the MatStepperIntl service
12+
*/
13+
@Component({
14+
selector: 'stepper-intl-example',
15+
templateUrl: 'stepper-intl-example.html',
16+
styleUrls: ['stepper-intl-example.css'],
17+
providers: [{ provide: MatStepperIntl, useClass: StepperIntl }]
18+
})
19+
export class StepperIntlExample implements OnInit {
20+
firstFormGroup: FormGroup;
21+
secondFormGroup: FormGroup;
22+
optionalLabelText: string;
23+
optionalLabelTextChoices: string[] = ['Option 1', 'Option 2', 'Option 3'];
24+
25+
constructor(
26+
private _formBuilder: FormBuilder,
27+
private _matStepperIntl: MatStepperIntl
28+
) {}
29+
30+
updateOptionalLabel() {
31+
this._matStepperIntl.optionalLabel = this.optionalLabelText;
32+
// Required for optional label text to be updated
33+
this._matStepperIntl.changes.next();
34+
}
35+
36+
ngOnInit() {
37+
this.firstFormGroup = this._formBuilder.group({
38+
firstCtrl: ['', Validators.required]
39+
});
40+
this.secondFormGroup = this._formBuilder.group({
41+
secondCtrl: ['', Validators.required]
42+
});
43+
}
44+
}

src/material/stepper/stepper.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ can be done by providing a subclass with translated values in your application r
217217
export class MyApp {}
218218
```
219219

220+
<!-- example(stepper-intl) -->
221+
220222
### Accessibility
221223
The stepper is treated as a tabbed view for accessibility purposes, so it is given
222224
`role="tablist"` by default. The header of step that can be clicked to select the step

0 commit comments

Comments
 (0)