@@ -149,13 +149,17 @@ export class CdkStepper {
149149 @Input ( )
150150 get selectedIndex ( ) { return this . _selectedIndex ; }
151151 set selectedIndex ( index : number ) {
152- if ( this . _anyControlsInvalid ( index )
153- || index < this . _selectedIndex && ! this . _steps . toArray ( ) [ index ] . editable ) {
154- // remove focus from clicked step header if the step is not able to be selected
155- this . _stepHeader . toArray ( ) [ index ] . nativeElement . blur ( ) ;
156- } else if ( this . _selectedIndex != index ) {
157- this . _emitStepperSelectionEvent ( index ) ;
158- this . _focusIndex = this . _selectedIndex ;
152+ if ( this . _steps ) {
153+ if ( this . _anyControlsInvalid ( index ) || index < this . _selectedIndex &&
154+ ! this . _steps . toArray ( ) [ index ] . editable ) {
155+ // remove focus from clicked step header if the step is not able to be selected
156+ this . _stepHeader . toArray ( ) [ index ] . nativeElement . blur ( ) ;
157+ } else if ( this . _selectedIndex != index ) {
158+ this . _emitStepperSelectionEvent ( index ) ;
159+ this . _focusIndex = this . _selectedIndex ;
160+ }
161+ } else {
162+ this . _selectedIndex = this . _focusIndex = index ;
159163 }
160164 }
161165 private _selectedIndex : number = 0 ;
@@ -281,9 +285,12 @@ export class CdkStepper {
281285 }
282286
283287 private _anyControlsInvalid ( index : number ) : boolean {
284- this . _steps . toArray ( ) [ this . _selectedIndex ] . interacted = true ;
288+ const steps = this . _steps . toArray ( ) ;
289+
290+ steps [ this . _selectedIndex ] . interacted = true ;
291+
285292 if ( this . _linear && index >= 0 ) {
286- return this . _steps . toArray ( ) . slice ( 0 , index ) . some ( step => step . stepControl . invalid ) ;
293+ return steps . slice ( 0 , index ) . some ( step => step . stepControl && step . stepControl . invalid ) ;
287294 }
288295 return false ;
289296 }
0 commit comments