@@ -149,13 +149,17 @@ export class CdkStepper {
149
149
@Input ( )
150
150
get selectedIndex ( ) { return this . _selectedIndex ; }
151
151
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 ;
159
163
}
160
164
}
161
165
private _selectedIndex : number = 0 ;
@@ -281,9 +285,12 @@ export class CdkStepper {
281
285
}
282
286
283
287
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
+
285
292
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 ) ;
287
294
}
288
295
return false ;
289
296
}
0 commit comments