|
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, |
@@ -276,19 +276,21 @@ export class CdkStepper implements AfterViewInit, OnDestroy { |
276 | 276 | @Input() |
277 | 277 | get selectedIndex() { return this._selectedIndex; } |
278 | 278 | set selectedIndex(index: number) { |
| 279 | + const newIndex = coerceNumberProperty(index); |
| 280 | + |
279 | 281 | if (this.steps) { |
280 | 282 | // Ensure that the index can't be out of bounds. |
281 | | - if (index < 0 || index > this.steps.length - 1) { |
| 283 | + if (newIndex < 0 || newIndex > this.steps.length - 1) { |
282 | 284 | throw Error('cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.'); |
283 | 285 | } |
284 | 286 |
|
285 | | - if (this._selectedIndex != index && |
286 | | - !this._anyControlsInvalidOrPending(index) && |
287 | | - (index >= this._selectedIndex || this.steps.toArray()[index].editable)) { |
| 287 | + if (this._selectedIndex != newIndex && |
| 288 | + !this._anyControlsInvalidOrPending(newIndex) && |
| 289 | + (newIndex >= this._selectedIndex || this.steps.toArray()[newIndex].editable)) { |
288 | 290 | this._updateSelectedItemIndex(index); |
289 | 291 | } |
290 | 292 | } else { |
291 | | - this._selectedIndex = index; |
| 293 | + this._selectedIndex = newIndex; |
292 | 294 | } |
293 | 295 | } |
294 | 296 | private _selectedIndex = 0; |
|
0 commit comments