Skip to content

Commit 891b4ac

Browse files
author
Abderrahmane Hamila
committed
fix(cdk-stepper): coercing selectedIndex value to a Number
1 parent 4701c7b commit 891b4ac

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/cdk/stepper/stepper.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
1010
import {Direction, Directionality} from '@angular/cdk/bidi';
11-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
11+
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
1212
import {END, ENTER, HOME, SPACE, hasModifierKey} from '@angular/cdk/keycodes';
1313
import {
1414
AfterViewInit,
@@ -267,19 +267,21 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
267267
@Input()
268268
get selectedIndex() { return this._selectedIndex; }
269269
set selectedIndex(index: number) {
270+
const newIndex = coerceNumberProperty(index);
271+
270272
if (this._steps) {
271273
// Ensure that the index can't be out of bounds.
272-
if (index < 0 || index > this._steps.length - 1) {
274+
if (newIndex < 0 || newIndex > this._steps.length - 1) {
273275
throw Error('cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.');
274276
}
275277

276-
if (this._selectedIndex != index &&
277-
!this._anyControlsInvalidOrPending(index) &&
278-
(index >= this._selectedIndex || this._steps.toArray()[index].editable)) {
278+
if (this._selectedIndex != newIndex &&
279+
!this._anyControlsInvalidOrPending(newIndex) &&
280+
(newIndex >= this._selectedIndex || this._steps.toArray()[newIndex].editable)) {
279281
this._updateSelectedItemIndex(index);
280282
}
281283
} else {
282-
this._selectedIndex = index;
284+
this._selectedIndex = newIndex;
283285
}
284286
}
285287
private _selectedIndex = 0;

0 commit comments

Comments
 (0)