Skip to content

feat(stepper): Create stepper button directives to enable adding buttons to stepper #5951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cdk/stepper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {NgModule} from '@angular/core';
import {CdkStepper, CdkStep} from './stepper';
import {CommonModule} from '@angular/common';
import {CdkStepLabel} from './step-label';
import {CdkStepperNext, CdkStepperPrevious} from './stepper-button';

@NgModule({
imports: [CommonModule],
exports: [CdkStep, CdkStepper, CdkStepLabel],
declarations: [CdkStep, CdkStepper, CdkStepLabel]
exports: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious],
declarations: [CdkStep, CdkStepper, CdkStepLabel, CdkStepperNext, CdkStepperPrevious]
})
export class CdkStepperModule {}

export * from './stepper';
export * from './step-label';
export * from './stepper-button';
28 changes: 28 additions & 0 deletions src/cdk/stepper/stepper-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Directive} from '@angular/core';
import {CdkStepper} from './stepper';

/** Button that moves to the next step in a stepper workflow. */
@Directive({
selector: 'button[cdkStepperNext]',
host: {'(click)': '_stepper.next()'}
})
export class CdkStepperNext {
constructor(public _stepper: CdkStepper) { }
}

/** Button that moves to the previous step in a stepper workflow. */
@Directive({
selector: 'button[cdkStepperPrevious]',
host: {'(click)': '_stepper.previous()'}
})
export class CdkStepperPrevious {
constructor(public _stepper: CdkStepper) { }
}
12 changes: 12 additions & 0 deletions src/demo-app/stepper/stepper-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ <h2>Horizontal Stepper Demo</h2>
<md-input-container>
<input mdInput placeholder="Answer" [(ngModel)]="step.content">
</md-input-container>
<div>
<button md-button mdStepperPrevious>Back</button>
<button md-button mdStepperNext>Next</button>
</div>
</md-step>
</md-horizontal-stepper>

Expand All @@ -14,6 +18,10 @@ <h2>Horizontal Stepper Demo with Templated Label</h2>
<md-input-container>
<input mdInput placeholder="Answer" [(ngModel)]="step.content">
</md-input-container>
<div>
<button md-button mdStepperPrevious>Back</button>
<button md-button mdStepperNext>Next</button>
</div>
</md-step>
</md-horizontal-stepper>

Expand All @@ -23,5 +31,9 @@ <h2>Vertical Stepper Demo</h2>
<md-input-container>
<input mdInput placeholder="Answer" [(ngModel)]="step.content">
</md-input-container>
<div>
<button md-button mdStepperPrevious>Back</button>
<button md-button mdStepperNext>Next</button>
</div>
</md-step>
</md-vertical-stepper>
4 changes: 4 additions & 0 deletions src/lib/core/compatibility/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const MAT_ELEMENTS_SELECTOR = `
[matDialogTitle],
[matLine],
[matStepLabel],
[matStepperNext],
[matStepperPrevious],
[matTabLabel],
[matTabLink],
[matTabNav],
Expand Down Expand Up @@ -105,6 +107,8 @@ export const MD_ELEMENTS_SELECTOR = `
[mdDialogTitle],
[mdLine],
[mdStepLabel],
[mdStepperNext],
[mdStepperPrevious],
[mdTabLabel],
[mdTabLink],
[mdTabNav],
Expand Down
8 changes: 6 additions & 2 deletions src/lib/stepper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import {MdStep, MdStepper} from './stepper';
import {CdkStepperModule} from '@angular/cdk';
import {MdCommonModule} from '../core';
import {MdStepLabel} from './step-label';
import {MdStepperNext, MdStepperPrevious} from './stepper-button';

@NgModule({
imports: [MdCommonModule, CommonModule, PortalModule, MdButtonModule, CdkStepperModule],
exports: [MdCommonModule, MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper],
declarations: [MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper],
exports: [MdCommonModule, MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper,
MdStepperNext, MdStepperPrevious],
declarations: [MdHorizontalStepper, MdVerticalStepper, MdStep, MdStepLabel, MdStepper,
MdStepperNext, MdStepperPrevious],
})
export class MdStepperModule {}

export * from './stepper-horizontal';
export * from './stepper-vertical';
export * from './step-label';
export * from './stepper';
export * from './stepper-button';
27 changes: 27 additions & 0 deletions src/lib/stepper/stepper-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Directive} from '@angular/core';
import {CdkStepper, CdkStepperNext, CdkStepperPrevious} from '@angular/cdk';
import {MdStepper} from './stepper';

/** Button that moves to the next step in a stepper workflow. */
@Directive({
selector: 'button[mdStepperNext], button[matStepperNext]',
host: {'(click)': '_stepper.next()'},
providers: [{provide: CdkStepper, useExisting: MdStepper}]
})
export class MdStepperNext extends CdkStepperNext { }

/** Button that moves to the previous step in a stepper workflow. */
@Directive({
selector: 'button[mdStepperPrevious], button[matStepperPrevious]',
host: {'(click)': '_stepper.previous()'},
providers: [{provide: CdkStepper, useExisting: MdStepper}]
})
export class MdStepperPrevious extends CdkStepperPrevious { }
5 changes: 0 additions & 5 deletions src/lib/stepper/stepper-horizontal.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,3 @@
[attr.aria-expanded]="selectedIndex == i">
<ng-container [ngTemplateOutlet]="step.content"></ng-container>
</div>
<!-- TODO(jwshin): Remove these buttons when stepper-button directives are created. -->
<div>
<button md-button (click)="previous()">Back</button>
<button md-button (click)="next()">Next</button>
</div>
6 changes: 0 additions & 6 deletions src/lib/stepper/stepper-vertical.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@
[attr.aria-labelledby]="_getStepLabelId(i)"
[attr.aria-expanded]="selectedIndex == i">
<ng-container [ngTemplateOutlet]="step.content"></ng-container>

<!-- TODO(jwshin): Remove these buttons when stepper-button directives are created. -->
<div>
<button md-button (click)="previous()">Back</button>
<button md-button (click)="next()">Next</button>
</div>
</div>
</div>