|
8 | 8 |
|
9 | 9 | import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
|
10 | 10 | import {Direction, Directionality} from '@angular/cdk/bidi';
|
11 |
| -import {coerceBooleanProperty} from '@angular/cdk/coercion'; |
| 11 | +import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion'; |
12 | 12 | import {END, ENTER, HOME, SPACE, hasModifierKey} from '@angular/cdk/keycodes';
|
13 | 13 | import {
|
14 | 14 | AfterViewInit,
|
@@ -267,19 +267,21 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
|
267 | 267 | @Input()
|
268 | 268 | get selectedIndex() { return this._selectedIndex; }
|
269 | 269 | set selectedIndex(index: number) {
|
| 270 | + const newIndex = coerceNumberProperty(index); |
| 271 | + |
270 | 272 | if (this._steps) {
|
271 | 273 | // 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) { |
273 | 275 | throw Error('cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.');
|
274 | 276 | }
|
275 | 277 |
|
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)) { |
279 | 281 | this._updateSelectedItemIndex(index);
|
280 | 282 | }
|
281 | 283 | } else {
|
282 |
| - this._selectedIndex = index; |
| 284 | + this._selectedIndex = newIndex; |
283 | 285 | }
|
284 | 286 | }
|
285 | 287 | private _selectedIndex = 0;
|
|
0 commit comments