8
8
9
9
import { FocusableOption , FocusKeyManager } from '@angular/cdk/a11y' ;
10
10
import { Direction , Directionality } from '@angular/cdk/bidi' ;
11
- import {
12
- BooleanInput ,
13
- coerceBooleanProperty ,
14
- coerceNumberProperty ,
15
- NumberInput ,
16
- } from '@angular/cdk/coercion' ;
17
11
import { ENTER , hasModifierKey , SPACE } from '@angular/cdk/keycodes' ;
18
12
import {
19
13
AfterViewInit ,
@@ -38,6 +32,8 @@ import {
38
32
ViewChild ,
39
33
ViewEncapsulation ,
40
34
AfterContentInit ,
35
+ booleanAttribute ,
36
+ numberAttribute ,
41
37
} from '@angular/core' ;
42
38
import { _getFocusedElementPierceShadowDom } from '@angular/cdk/platform' ;
43
39
import { Observable , of as observableOf , Subject } from 'rxjs' ;
@@ -149,32 +145,18 @@ export class CdkStep implements OnChanges {
149
145
@Input ( ) state : StepState ;
150
146
151
147
/** Whether the user can return to this step once it has been marked as completed. */
152
- @Input ( )
153
- get editable ( ) : boolean {
154
- return this . _editable ;
155
- }
156
- set editable ( value : BooleanInput ) {
157
- this . _editable = coerceBooleanProperty ( value ) ;
158
- }
159
- private _editable = true ;
148
+ @Input ( { transform : booleanAttribute } ) editable : boolean = true ;
160
149
161
150
/** Whether the completion of step is optional. */
162
- @Input ( )
163
- get optional ( ) : boolean {
164
- return this . _optional ;
165
- }
166
- set optional ( value : BooleanInput ) {
167
- this . _optional = coerceBooleanProperty ( value ) ;
168
- }
169
- private _optional = false ;
151
+ @Input ( { transform : booleanAttribute } ) optional : boolean = false ;
170
152
171
153
/** Whether step is marked as completed. */
172
- @Input ( )
154
+ @Input ( { transform : booleanAttribute } )
173
155
get completed ( ) : boolean {
174
156
return this . _completedOverride == null ? this . _getDefaultCompleted ( ) : this . _completedOverride ;
175
157
}
176
- set completed ( value : BooleanInput ) {
177
- this . _completedOverride = coerceBooleanProperty ( value ) ;
158
+ set completed ( value : boolean ) {
159
+ this . _completedOverride = value ;
178
160
}
179
161
_completedOverride : boolean | null = null ;
180
162
@@ -183,12 +165,12 @@ export class CdkStep implements OnChanges {
183
165
}
184
166
185
167
/** Whether step has an error. */
186
- @Input ( )
168
+ @Input ( { transform : booleanAttribute } )
187
169
get hasError ( ) : boolean {
188
170
return this . _customError == null ? this . _getDefaultError ( ) : this . _customError ;
189
171
}
190
- set hasError ( value : BooleanInput ) {
191
- this . _customError = coerceBooleanProperty ( value ) ;
172
+ set hasError ( value : boolean ) {
173
+ this . _customError = value ;
192
174
}
193
175
private _customError : boolean | null = null ;
194
176
@@ -271,40 +253,31 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
271
253
private _sortedHeaders = new QueryList < CdkStepHeader > ( ) ;
272
254
273
255
/** Whether the validity of previous steps should be checked or not. */
274
- @Input ( )
275
- get linear ( ) : boolean {
276
- return this . _linear ;
277
- }
278
- set linear ( value : BooleanInput ) {
279
- this . _linear = coerceBooleanProperty ( value ) ;
280
- }
281
- private _linear = false ;
256
+ @Input ( { transform : booleanAttribute } ) linear : boolean = false ;
282
257
283
258
/** The index of the selected step. */
284
- @Input ( )
259
+ @Input ( { transform : numberAttribute } )
285
260
get selectedIndex ( ) : number {
286
261
return this . _selectedIndex ;
287
262
}
288
- set selectedIndex ( index : NumberInput ) {
289
- const newIndex = coerceNumberProperty ( index ) ;
290
-
263
+ set selectedIndex ( index : number ) {
291
264
if ( this . steps && this . _steps ) {
292
265
// Ensure that the index can't be out of bounds.
293
- if ( ! this . _isValidIndex ( newIndex ) && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
266
+ if ( ! this . _isValidIndex ( index ) && ( typeof ngDevMode === 'undefined' || ngDevMode ) ) {
294
267
throw Error ( 'cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.' ) ;
295
268
}
296
269
297
270
this . selected ?. _markAsInteracted ( ) ;
298
271
299
272
if (
300
- this . _selectedIndex !== newIndex &&
301
- ! this . _anyControlsInvalidOrPending ( newIndex ) &&
302
- ( newIndex >= this . _selectedIndex || this . steps . toArray ( ) [ newIndex ] . editable )
273
+ this . _selectedIndex !== index &&
274
+ ! this . _anyControlsInvalidOrPending ( index ) &&
275
+ ( index >= this . _selectedIndex || this . steps . toArray ( ) [ index ] . editable )
303
276
) {
304
- this . _updateSelectedItemIndex ( newIndex ) ;
277
+ this . _updateSelectedItemIndex ( index ) ;
305
278
}
306
279
} else {
307
- this . _selectedIndex = newIndex ;
280
+ this . _selectedIndex = index ;
308
281
}
309
282
}
310
283
private _selectedIndex = 0 ;
@@ -551,7 +524,7 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
551
524
}
552
525
553
526
private _anyControlsInvalidOrPending ( index : number ) : boolean {
554
- if ( this . _linear && index >= 0 ) {
527
+ if ( this . linear && index >= 0 ) {
555
528
return this . steps
556
529
. toArray ( )
557
530
. slice ( 0 , index )
0 commit comments