Skip to content

Commit

Permalink
fix(stepper): selected is always undefined (#7213)
Browse files Browse the repository at this point in the history
  • Loading branch information
NothingEverHappens authored and andrewseguin committed Sep 29, 2017
1 parent ba5653d commit 217840c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class CdkStepper {

/** The step that is selected. */
@Input()
get selected() { return this._steps[this.selectedIndex]; }
get selected() { return this._steps.toArray()[this.selectedIndex]; }
set selected(step: CdkStep) {
this.selectedIndex = this._steps.toArray().indexOf(step);
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {MatStepperModule} from './index';
import {MatHorizontalStepper, MatStepper, MatVerticalStepper} from './stepper';
import {MatStepperNext, MatStepperPrevious} from './stepper-button';


const VALID_REGEX = /valid/;

describe('MatHorizontalStepper', () => {
Expand Down Expand Up @@ -307,20 +306,23 @@ function assertSelectionChangeOnHeaderClick(fixture: ComponentFixture<any>,
let stepperComponent = fixture.debugElement.query(By.directive(MatStepper)).componentInstance;

expect(stepperComponent.selectedIndex).toBe(0);
expect(stepperComponent.selected instanceof MdStep).toBe(true);

// select the second step
let stepHeaderEl = stepHeaders[1].nativeElement;
stepHeaderEl.click();
fixture.detectChanges();

expect(stepperComponent.selectedIndex).toBe(1);
expect(stepperComponent.selected instanceof MdStep).toBe(true);

// select the third step
stepHeaderEl = stepHeaders[2].nativeElement;
stepHeaderEl.click();
fixture.detectChanges();

expect(stepperComponent.selectedIndex).toBe(2);
expect(stepperComponent.selected instanceof MdStep).toBe(true);
}

/** Asserts that 'aria-expanded' attribute is correct for expanded content of step. */
Expand Down

0 comments on commit 217840c

Please sign in to comment.