Skip to content

refactor(stepper): rework buttons to handle Ivy (#15429) #15463

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 1 commit into from
Mar 13, 2019
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
25 changes: 22 additions & 3 deletions src/cdk/stepper/stepper-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, Input} from '@angular/core';
import {Directive, HostListener, Input} 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()',
'[type]': 'type',
}
})
Expand All @@ -22,13 +22,22 @@ export class CdkStepperNext {
@Input() type: string = 'submit';

constructor(public _stepper: CdkStepper) {}

// We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
// In Ivy the `host` bindings will be merged when this class is extended, whereas in
// ViewEngine they're overwritte.
// TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
// tslint:disable-next-line:no-host-decorator-in-concrete
@HostListener('click')
_handleClick() {
this._stepper.next();
}
}

/** Button that moves to the previous step in a stepper workflow. */
@Directive({
selector: 'button[cdkStepperPrevious]',
host: {
'(click)': '_stepper.previous()',
'[type]': 'type',
}
})
Expand All @@ -37,4 +46,14 @@ export class CdkStepperPrevious {
@Input() type: string = 'button';

constructor(public _stepper: CdkStepper) {}

// We have to use a `HostListener` here in order to support both Ivy and ViewEngine.
// In Ivy the `host` bindings will be merged when this class is extended, whereas in
// ViewEngine they're overwritte.
// TODO(crisbeto): we move this back into `host` once Ivy is turned on by default.
// tslint:disable-next-line:no-host-decorator-in-concrete
@HostListener('click')
_handleClick() {
this._stepper.previous();
}
}
17 changes: 7 additions & 10 deletions src/lib/stepper/stepper-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,27 @@
* found in the LICENSE file at https://angular.io/license
*/

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

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

/** Button that moves to the previous step in a stepper workflow. */
@Directive({
selector: 'button[matStepperPrevious]',
host: {
'(click)': '_stepper.previous()',
'[type]': 'type',
},
inputs: ['type'],
providers: [{provide: CdkStepper, useExisting: MatStepper}]
inputs: ['type']
})
export class MatStepperPrevious extends CdkStepperPrevious {}
export class MatStepperPrevious extends CdkStepperPrevious {
}
14 changes: 9 additions & 5 deletions src/lib/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ export class MatStep extends CdkStep implements ErrorStateMatcher {
}


@Directive({
selector: '[matStepper]'
})
@Directive({selector: '[matStepper]', providers: [{provide: CdkStepper, useExisting: MatStepper}]})
export class MatStepper extends CdkStepper implements AfterContentInit {
/** The list of step headers of the steps in the stepper. */
@ViewChildren(MatStepHeader) _stepHeader: QueryList<MatStepHeader>;
Expand Down Expand Up @@ -138,7 +136,10 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
'role': 'tablist',
},
animations: [matStepperAnimations.horizontalStepTransition],
providers: [{provide: MatStepper, useExisting: MatHorizontalStepper}],
providers: [
{provide: MatStepper, useExisting: MatHorizontalStepper},
{provide: CdkStepper, useExisting: MatHorizontalStepper}
],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand All @@ -161,7 +162,10 @@ export class MatHorizontalStepper extends MatStepper {
'role': 'tablist',
},
animations: [matStepperAnimations.verticalStepTransition],
providers: [{provide: MatStepper, useExisting: MatVerticalStepper}],
providers: [
{provide: MatStepper, useExisting: MatVerticalStepper},
{provide: CdkStepper, useExisting: MatVerticalStepper}
],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/cdk/stepper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ export declare class CdkStepperNext {
_stepper: CdkStepper;
type: string;
constructor(_stepper: CdkStepper);
_handleClick(): void;
}

export declare class CdkStepperPrevious {
_stepper: CdkStepper;
type: string;
constructor(_stepper: CdkStepper);
_handleClick(): void;
}

export declare const MAT_STEPPER_GLOBAL_OPTIONS: InjectionToken<StepperOptions>;
Expand Down