Skip to content

Commit c19aabe

Browse files
authored
docs(material/stepper): add example with MatStepperIntl service (#22685)
1 parent 2600d4a commit c19aabe

File tree

6 files changed

+132
-1
lines changed

6 files changed

+132
-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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<label for="demo-optional-label-group">Pick the text for the optional label</label>
2+
<mat-radio-group
3+
id="demo-optional-label-group"
4+
class="demo-radio-group"
5+
[(ngModel)]="optionalLabelText"
6+
(ngModelChange)="updateOptionalLabel()">
7+
<mat-radio-button
8+
class="demo-radio-button"
9+
*ngFor="let optionalLabelTextChoice of optionalLabelTextChoices"
10+
[value]="optionalLabelTextChoice">
11+
{{optionalLabelTextChoice}}
12+
</mat-radio-button>
13+
</mat-radio-group>
14+
<mat-horizontal-stepper class="demo-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 class="demo-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+
<form [formGroup]="secondFormGroup">
37+
<mat-form-field>
38+
<mat-label>Address</mat-label>
39+
<input
40+
matInput
41+
formControlName="secondCtrl"
42+
placeholder="Ex. 1 Main St, New York, NY"
43+
/>
44+
</mat-form-field>
45+
<div>
46+
<button mat-button matStepperPrevious>Back</button>
47+
<button mat-button matStepperNext>Next</button>
48+
</div>
49+
</form>
50+
</mat-step>
51+
<mat-step>
52+
<ng-template matStepLabel>Done</ng-template>
53+
<p>You are now done.</p>
54+
<div>
55+
<button mat-button matStepperPrevious>Back</button>
56+
<button mat-button (click)="stepper.reset()">Reset</button>
57+
</div>
58+
</mat-step>
59+
</mat-horizontal-stepper>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {Component, Injectable, OnInit} from '@angular/core';
2+
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3+
import {MatStepperIntl} from '@angular/material/stepper';
4+
5+
@Injectable()
6+
export class StepperIntl extends MatStepperIntl {
7+
// the default optional label text, if unspecified is "Optional"
8+
optionalLabel = 'Optional Label';
9+
}
10+
11+
/**
12+
* @title Stepper that uses the MatStepperIntl service
13+
*/
14+
@Component({
15+
selector: 'stepper-intl-example',
16+
templateUrl: 'stepper-intl-example.html',
17+
styleUrls: ['stepper-intl-example.css'],
18+
providers: [{ provide: MatStepperIntl, useClass: StepperIntl }]
19+
})
20+
export class StepperIntlExample implements OnInit {
21+
firstFormGroup: FormGroup;
22+
secondFormGroup: FormGroup;
23+
optionalLabelText: string;
24+
optionalLabelTextChoices: string[] = ['Option 1', 'Option 2', 'Option 3'];
25+
26+
constructor(
27+
private _formBuilder: FormBuilder,
28+
private _matStepperIntl: MatStepperIntl
29+
) {}
30+
31+
updateOptionalLabel() {
32+
this._matStepperIntl.optionalLabel = this.optionalLabelText;
33+
// Required for the optional label text to be updated
34+
// Notifies the MatStepperIntl service that a change has been made
35+
this._matStepperIntl.changes.next();
36+
}
37+
38+
ngOnInit() {
39+
this.firstFormGroup = this._formBuilder.group({
40+
firstCtrl: ['', Validators.required]
41+
});
42+
this.secondFormGroup = this._formBuilder.group({
43+
secondCtrl: ['', Validators.required]
44+
});
45+
}
46+
}

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)