Skip to content

Commit 68d321e

Browse files
committed
feat(stepper): Create stepper button directives to enable adding buttons to stepper (#5951)
* Create stepper button directives to enable adding buttons to stepper * Changes made based on review * Minor changes with click handlers
1 parent 4d77d50 commit 68d321e

File tree

8 files changed

+81
-15
lines changed

8 files changed

+81
-15
lines changed

src/cdk/stepper/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import {NgModule} from '@angular/core';
1010
import {CdkStepper, CdkStep} from './stepper';
1111
import {CommonModule} from '@angular/common';
1212
import {CdkStepLabel} from './step-label';
13+
import {CdkStepperNext, CdkStepperPrevious} from './stepper-button';
1314

1415
@NgModule({
1516
imports: [CommonModule],
16-
exports: [CdkStep, CdkStepper, CdkStepLabel],
17-
declarations: [CdkStep, CdkStepper, CdkStepLabel]
17+
exports: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious],
18+
declarations: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious]
1819
})
1920
export class CdkStepperModule {}
2021

2122
export * from './stepper';
2223
export * from './step-label';
24+
export * from './stepper-button';

src/cdk/stepper/stepper-button.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Directive} from '@angular/core';
10+
import {CdkStepper} from './stepper';
11+
12+
/** Button that moves to the next step in a stepper workflow. */
13+
@Directive({
14+
selector: 'button[cdkStepperNext]',
15+
host: {'(click)': '_stepper.next()'}
16+
})
17+
export class CdkStepperNext {
18+
constructor(public _stepper: CdkStepper) { }
19+
}
20+
21+
/** Button that moves to the previous step in a stepper workflow. */
22+
@Directive({
23+
selector: 'button[cdkStepperPrevious]',
24+
host: {'(click)': '_stepper.previous()'}
25+
})
26+
export class CdkStepperPrevious {
27+
constructor(public _stepper: CdkStepper) { }
28+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ <h2>Horizontal Stepper Demo</h2>
44
<md-input-container>
55
<input mdInput placeholder="Answer" [(ngModel)]="step.content">
66
</md-input-container>
7+
<div>
8+
<button md-button mdStepperPrevious>Back</button>
9+
<button md-button mdStepperNext>Next</button>
10+
</div>
711
</md-step>
812
</md-horizontal-stepper>
913

@@ -14,6 +18,10 @@ <h2>Horizontal Stepper Demo with Templated Label</h2>
1418
<md-input-container>
1519
<input mdInput placeholder="Answer" [(ngModel)]="step.content">
1620
</md-input-container>
21+
<div>
22+
<button md-button mdStepperPrevious>Back</button>
23+
<button md-button mdStepperNext>Next</button>
24+
</div>
1725
</md-step>
1826
</md-horizontal-stepper>
1927

@@ -23,5 +31,9 @@ <h2>Vertical Stepper Demo</h2>
2331
<md-input-container>
2432
<input mdInput placeholder="Answer" [(ngModel)]="step.content">
2533
</md-input-container>
34+
<div>
35+
<button md-button mdStepperPrevious>Back</button>
36+
<button md-button mdStepperNext>Next</button>
37+
</div>
2638
</md-step>
2739
</md-vertical-stepper>

src/lib/core/compatibility/compatibility.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const MAT_ELEMENTS_SELECTOR = `
4040
[matLine],
4141
[matRowDef],
4242
[matStepLabel],
43+
[matStepperNext],
44+
[matStepperPrevious],
4345
[matTabLabel],
4446
[matTabLink],
4547
[matTabNav],
@@ -120,6 +122,8 @@ export const MD_ELEMENTS_SELECTOR = `
120122
[mdLine],
121123
[mdRowDef],
122124
[mdStepLabel],
125+
[mdStepperNext],
126+
[mdStepperPrevious],
123127
[mdTabLabel],
124128
[mdTabLink],
125129
[mdTabNav],

src/lib/stepper/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ import {MdStep, MdStepper} from './stepper';
1616
import {CdkStepperModule} from '@angular/cdk';
1717
import {MdCommonModule} from '../core';
1818
import {MdStepLabel} from './step-label';
19+
import {MdStepperNext, MdStepperPrevious} from './stepper-button';
1920

2021
@NgModule({
2122
imports: [MdCommonModule, CommonModule, PortalModule, MdButtonModule, CdkStepperModule],
22-
exports: [MdCommonModule, MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper],
23-
declarations: [MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper],
23+
exports: [MdCommonModule, MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper,
24+
MdStepperNext, MdStepperPrevious],
25+
declarations: [MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper,
26+
MdStepperNext, MdStepperPrevious],
2427
})
2528
export class MdStepperModule {}
2629

2730
export * from './stepper-horizontal';
2831
export * from './stepper-vertical';
2932
export * from './step-label';
3033
export * from './stepper';
34+
export * from './stepper-button';

src/lib/stepper/stepper-button.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Directive} from '@angular/core';
10+
import {CdkStepper, CdkStepperNext, CdkStepperPrevious} from '@angular/cdk';
11+
import {MdStepper} from './stepper';
12+
13+
/** Button that moves to the next step in a stepper workflow. */
14+
@Directive({
15+
selector: 'button[mdStepperNext], button[matStepperNext]',
16+
host: {'(click)': '_stepper.next()'},
17+
providers: [{provide: CdkStepper, useExisting: MdStepper}]
18+
})
19+
export class MdStepperNext extends CdkStepperNext { }
20+
21+
/** Button that moves to the previous step in a stepper workflow. */
22+
@Directive({
23+
selector: 'button[mdStepperPrevious], button[matStepperPrevious]',
24+
host: {'(click)': '_stepper.previous()'},
25+
providers: [{provide: CdkStepper, useExisting: MdStepper}]
26+
})
27+
export class MdStepperPrevious extends CdkStepperPrevious { }

src/lib/stepper/stepper-horizontal.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,3 @@
2828
[attr.aria-expanded]="selectedIndex == i">
2929
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
3030
</div>
31-
<!-- TODO(jwshin): Remove these buttons when stepper-button directives are created. -->
32-
<div>
33-
<button md-button (click)="previous()">Back</button>
34-
<button md-button (click)="next()">Next</button>
35-
</div>

src/lib/stepper/stepper-vertical.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,5 @@
2525
[attr.aria-labelledby]="_getStepLabelId(i)"
2626
[attr.aria-expanded]="selectedIndex == i">
2727
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
28-
29-
<!-- TODO(jwshin): Remove these buttons when stepper-button directives are created. -->
30-
<div>
31-
<button md-button (click)="previous()">Back</button>
32-
<button md-button (click)="next()">Next</button>
33-
</div>
3428
</div>
3529
</div>

0 commit comments

Comments
 (0)