Skip to content

Commit bbf8138

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

File tree

6 files changed

+133
-1
lines changed

6 files changed

+133
-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+
.demo-stepper {
2+
margin-top: 8px;
3+
}
4+
5+
.demo-form-field {
6+
margin-top: 16px;
7+
}
8+
9+
.demo-radio-group {
10+
display: flex;
11+
flex-direction: column;
12+
margin: 15px 0;
13+
}
14+
15+
.demo-radio-button {
16+
margin: 5px;
17+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
class="demo-radio-group"
5+
[(ngModel)]="optionalLabelText"
6+
(ngModelChange)="updateOptionalLabel()"
7+
>
8+
<mat-radio-button
9+
class="demo-radio-button"
10+
*ngFor="let optionalLabelTextChoice of optionalLabelTextChoices"
11+
[value]="optionalLabelTextChoice"
12+
>
13+
{{optionalLabelTextChoice}}
14+
</mat-radio-button>
15+
</mat-radio-group>
16+
<mat-horizontal-stepper class="demo-stepper" #stepper>
17+
<mat-step [stepControl]="firstFormGroup">
18+
<form [formGroup]="firstFormGroup">
19+
<ng-template matStepLabel>Fill out your name</ng-template>
20+
<mat-form-field class="demo-form-field">
21+
<mat-label>Name</mat-label>
22+
<input
23+
matInput
24+
placeholder="Last name, First name"
25+
formControlName="firstCtrl"
26+
required
27+
/>
28+
</mat-form-field>
29+
<div>
30+
<button mat-button matStepperNext>Next</button>
31+
</div>
32+
</form>
33+
</mat-step>
34+
<mat-step
35+
[stepControl]="secondFormGroup"
36+
label="Fill out your address"
37+
optional
38+
>
39+
<form [formGroup]="secondFormGroup">
40+
<mat-form-field>
41+
<mat-label>Address</mat-label>
42+
<input
43+
matInput
44+
formControlName="secondCtrl"
45+
placeholder="Ex. 1 Main St, New York, NY"
46+
/>
47+
</mat-form-field>
48+
<div>
49+
<button mat-button matStepperPrevious>Back</button>
50+
<button mat-button matStepperNext>Next</button>
51+
</div>
52+
</form>
53+
</mat-step>
54+
<mat-step>
55+
<ng-template matStepLabel>Done</ng-template>
56+
<p>You are now done.</p>
57+
<div>
58+
<button mat-button matStepperPrevious>Back</button>
59+
<button mat-button (click)="stepper.reset()">Reset</button>
60+
</div>
61+
</mat-step>
62+
</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)