Skip to content
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
14 changes: 9 additions & 5 deletions src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
throw Error('cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.');
}

const selectedStep = this.selected;

if (selectedStep) {
// TODO: this should really be called something like `visited` instead. Just because
// the user has seen the step doesn't guarantee that they've interacted with it.
selectedStep.interacted = true;
}

if (this._selectedIndex !== newIndex && !this._anyControlsInvalidOrPending(newIndex) &&
(newIndex >= this._selectedIndex || this.steps.toArray()[newIndex].editable)) {
this._updateSelectedItemIndex(index);
Expand Down Expand Up @@ -500,12 +508,8 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
}

private _anyControlsInvalidOrPending(index: number): boolean {
const steps = this.steps.toArray();

steps[this._selectedIndex].interacted = true;

if (this._linear && index >= 0) {
return steps.slice(0, index).some(step => {
return this.steps.toArray().slice(0, index).some(step => {
const control = step.stepControl;
const isIncomplete =
control ? (control.invalid || control.pending || !step.interacted) : !step.completed;
Expand Down
22 changes: 22 additions & 0 deletions src/material/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,28 @@ describe('MatStepper', () => {
expect(headers[2].classList.contains('mat-primary')).toBe(true);
expect(headers[1].classList.contains('mat-accent')).toBe(true);
});

it('should be able to mark all steps as interacted', () => {
const fixture = createComponent(SimpleMatHorizontalStepperApp);
fixture.detectChanges();

const stepper: MatStepper =
fixture.debugElement.query(By.directive(MatStepper)).componentInstance;

expect(stepper.steps.map(step => step.interacted)).toEqual([false, false, false]);

stepper.next();
fixture.detectChanges();
expect(stepper.steps.map(step => step.interacted)).toEqual([true, false, false]);

stepper.next();
fixture.detectChanges();
expect(stepper.steps.map(step => step.interacted)).toEqual([true, true, false]);

stepper.next();
fixture.detectChanges();
expect(stepper.steps.map(step => step.interacted)).toEqual([true, true, true]);
});
});

describe('linear stepper with valid step', () => {
Expand Down