Skip to content

fix(stepper): overriding default completed logic when resetting #9650

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
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
5 changes: 4 additions & 1 deletion src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export class CdkStep implements OnChanges {
/** Resets the step to its initial state. Note that this includes resetting form data. */
reset(): void {
this.interacted = false;
this.completed = false;

if (this._customCompleted != null) {
this._customCompleted = false;
}

if (this.stepControl) {
this.stepControl.reset();
Expand Down
40 changes: 40 additions & 0 deletions src/lib/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ describe('MatHorizontalStepper', () => {
it('should be able to reset the stepper to its initial state', () => {
assertLinearStepperResetable(fixture);
});

it('should not clobber the `complete` binding when resetting', () => {
assertLinearStepperResetComplete(fixture);
});
});
});

Expand Down Expand Up @@ -457,6 +461,10 @@ describe('MatVerticalStepper', () => {
it('should be able to reset the stepper to its initial state', () => {
assertLinearStepperResetable(fixture);
});

it('should not clobber the `complete` binding when resetting', () => {
assertLinearStepperResetComplete(fixture);
});
});
});

Expand Down Expand Up @@ -935,6 +943,38 @@ function assertLinearStepperResetable(
}


/** Asserts that the `complete` binding is being reset correctly. */
function assertLinearStepperResetComplete(
fixture: ComponentFixture<LinearMatHorizontalStepperApp|LinearMatVerticalStepperApp>) {

const testComponent = fixture.componentInstance;
const stepperComponent = fixture.debugElement.query(By.directive(MatStepper)).componentInstance;
const steps: MatStep[] = stepperComponent._steps.toArray();
const fillOutStepper = () => {
testComponent.oneGroup.get('oneCtrl')!.setValue('input');
testComponent.twoGroup.get('twoCtrl')!.setValue('input');
testComponent.threeGroup.get('threeCtrl')!.setValue('valid');
testComponent.validationTrigger.next();
stepperComponent.selectedIndex = 2;
fixture.detectChanges();
stepperComponent.selectedIndex = 3;
fixture.detectChanges();
};

fillOutStepper();

expect(steps[2].completed)
.toBe(true, 'Expected third step to be considered complete after the first run through.');

stepperComponent.reset();
fixture.detectChanges();
fillOutStepper();

expect(steps[2].completed)
.toBe(true, 'Expected third step to be considered complete when doing a run after a reset.');
}


@Component({
template: `
<mat-horizontal-stepper>
Expand Down