9
9
import { FocusableOption , FocusKeyManager } from '@angular/cdk/a11y' ;
10
10
import { Direction , Directionality } from '@angular/cdk/bidi' ;
11
11
import { coerceBooleanProperty , coerceNumberProperty } from '@angular/cdk/coercion' ;
12
- import { END , ENTER , HOME , SPACE , hasModifierKey } from '@angular/cdk/keycodes' ;
12
+ import { END , ENTER , hasModifierKey , HOME , SPACE } from '@angular/cdk/keycodes' ;
13
+ import { DOCUMENT } from '@angular/common' ;
13
14
import {
14
15
AfterViewInit ,
15
16
ChangeDetectionStrategy ,
@@ -18,10 +19,11 @@ import {
18
19
ContentChild ,
19
20
ContentChildren ,
20
21
Directive ,
21
- EventEmitter ,
22
22
ElementRef ,
23
+ EventEmitter ,
23
24
forwardRef ,
24
25
Inject ,
26
+ InjectionToken ,
25
27
Input ,
26
28
OnChanges ,
27
29
OnDestroy ,
@@ -31,13 +33,12 @@ import {
31
33
TemplateRef ,
32
34
ViewChild ,
33
35
ViewEncapsulation ,
34
- InjectionToken ,
35
36
} from '@angular/core' ;
36
- import { DOCUMENT } from '@angular/common' ;
37
- import { CdkStepLabel } from './step-label' ;
38
- import { Observable , Subject , of as obaservableOf } from 'rxjs' ;
37
+ import { Observable , of as obaservableOf , Subject } from 'rxjs' ;
39
38
import { startWith , takeUntil } from 'rxjs/operators' ;
39
+
40
40
import { CdkStepHeader } from './step-header' ;
41
+ import { CdkStepLabel } from './step-label' ;
41
42
42
43
/** Used to generate unique ID for each stepper component. */
43
44
let nextId = 0 ;
@@ -46,10 +47,10 @@ let nextId = 0;
46
47
* Position state of the content of each step in stepper that is used for transitioning
47
48
* the content into correct position upon step selection change.
48
49
*/
49
- export type StepContentPositionState = 'previous' | 'current' | 'next' ;
50
+ export type StepContentPositionState = 'previous' | 'current' | 'next' ;
50
51
51
52
/** Possible orientation of a stepper. */
52
- export type StepperOrientation = 'horizontal' | 'vertical' ;
53
+ export type StepperOrientation = 'horizontal' | 'vertical' ;
53
54
54
55
/** Change event emitted on selection changes. */
55
56
export class StepperSelectionEvent {
@@ -67,7 +68,7 @@ export class StepperSelectionEvent {
67
68
}
68
69
69
70
/** The state of each step. */
70
- export type StepState = 'number' | 'edit' | 'done' | 'error' | string ;
71
+ export type StepState = 'number' | 'edit' | 'done' | 'error' | string ;
71
72
72
73
/** Enum to represent the different states of the steps. */
73
74
export const STEP_STATE = {
@@ -78,8 +79,7 @@ export const STEP_STATE = {
78
79
} ;
79
80
80
81
/** InjectionToken that can be used to specify the global stepper options. */
81
- export const STEPPER_GLOBAL_OPTIONS =
82
- new InjectionToken < StepperOptions > ( 'STEPPER_GLOBAL_OPTIONS' ) ;
82
+ export const STEPPER_GLOBAL_OPTIONS = new InjectionToken < StepperOptions > ( 'STEPPER_GLOBAL_OPTIONS' ) ;
83
83
84
84
/**
85
85
* InjectionToken that can be used to specify the global stepper options.
@@ -149,15 +149,19 @@ export class CdkStep implements OnChanges {
149
149
150
150
/** Whether the user can return to this step once it has been marked as completed. */
151
151
@Input ( )
152
- get editable ( ) : boolean { return this . _editable ; }
152
+ get editable ( ) : boolean {
153
+ return this . _editable ;
154
+ }
153
155
set editable ( value : boolean ) {
154
156
this . _editable = coerceBooleanProperty ( value ) ;
155
157
}
156
158
private _editable = true ;
157
159
158
160
/** Whether the completion of step is optional. */
159
161
@Input ( )
160
- get optional ( ) : boolean { return this . _optional ; }
162
+ get optional ( ) : boolean {
163
+ return this . _optional ;
164
+ }
161
165
set optional ( value : boolean ) {
162
166
this . _optional = coerceBooleanProperty ( value ) ;
163
167
}
@@ -166,12 +170,12 @@ export class CdkStep implements OnChanges {
166
170
/** Whether step is marked as completed. */
167
171
@Input ( )
168
172
get completed ( ) : boolean {
169
- return this . _customCompleted == null ? this . _getDefaultCompleted ( ) : this . _customCompleted ;
173
+ return this . _completedOverride == null ? this . _getDefaultCompleted ( ) : this . _completedOverride ;
170
174
}
171
175
set completed ( value : boolean ) {
172
- this . _customCompleted = coerceBooleanProperty ( value ) ;
176
+ this . _completedOverride = coerceBooleanProperty ( value ) ;
173
177
}
174
- private _customCompleted : boolean | null = null ;
178
+ _completedOverride : boolean | null = null ;
175
179
176
180
private _getDefaultCompleted ( ) {
177
181
return this . stepControl ? this . stepControl . valid && this . interacted : this . interacted ;
@@ -185,16 +189,16 @@ export class CdkStep implements OnChanges {
185
189
set hasError ( value : boolean ) {
186
190
this . _customError = coerceBooleanProperty ( value ) ;
187
191
}
188
- private _customError : boolean | null = null ;
192
+ private _customError : boolean | null = null ;
189
193
190
194
private _getDefaultError ( ) {
191
195
return this . stepControl && this . stepControl . invalid && this . interacted ;
192
196
}
193
197
194
198
/** @breaking -change 8.0.0 remove the `?` after `stepperOptions` */
195
199
constructor (
196
- @Inject ( forwardRef ( ( ) => CdkStepper ) ) private _stepper : CdkStepper ,
197
- @Optional ( ) @Inject ( STEPPER_GLOBAL_OPTIONS ) stepperOptions ?: StepperOptions ) {
200
+ @Inject ( forwardRef ( ( ) => CdkStepper ) ) private _stepper : CdkStepper ,
201
+ @Optional ( ) @Inject ( STEPPER_GLOBAL_OPTIONS ) stepperOptions ?: StepperOptions ) {
198
202
this . _stepperOptions = stepperOptions ? stepperOptions : { } ;
199
203
this . _displayDefaultIndicatorType = this . _stepperOptions . displayDefaultIndicatorType !== false ;
200
204
this . _showError = ! ! this . _stepperOptions . showError ;
@@ -209,8 +213,8 @@ export class CdkStep implements OnChanges {
209
213
reset ( ) : void {
210
214
this . interacted = false ;
211
215
212
- if ( this . _customCompleted != null ) {
213
- this . _customCompleted = false ;
216
+ if ( this . _completedOverride != null ) {
217
+ this . _completedOverride = false ;
214
218
}
215
219
216
220
if ( this . _customError != null ) {
@@ -244,7 +248,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
244
248
* @breaking -change 8.0.0 Remove `| undefined` once the `_document`
245
249
* constructor param is required.
246
250
*/
247
- private _document : Document | undefined ;
251
+ private _document : Document | undefined ;
248
252
249
253
/**
250
254
* The list of step components that the stepper is holding.
@@ -254,7 +258,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
254
258
@ContentChildren ( CdkStep ) _steps : QueryList < CdkStep > ;
255
259
256
260
/** The list of step components that the stepper is holding. */
257
- get steps ( ) : QueryList < CdkStep > {
261
+ get steps ( ) : QueryList < CdkStep > {
258
262
return this . _steps ;
259
263
}
260
264
@@ -267,13 +271,19 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
267
271
268
272
/** Whether the validity of previous steps should be checked or not. */
269
273
@Input ( )
270
- get linear ( ) : boolean { return this . _linear ; }
271
- set linear ( value : boolean ) { this . _linear = coerceBooleanProperty ( value ) ; }
274
+ get linear ( ) : boolean {
275
+ return this . _linear ;
276
+ }
277
+ set linear ( value : boolean ) {
278
+ this . _linear = coerceBooleanProperty ( value ) ;
279
+ }
272
280
private _linear = false ;
273
281
274
282
/** The index of the selected step. */
275
283
@Input ( )
276
- get selectedIndex ( ) { return this . _selectedIndex ; }
284
+ get selectedIndex ( ) {
285
+ return this . _selectedIndex ;
286
+ }
277
287
set selectedIndex ( index : number ) {
278
288
const newIndex = coerceNumberProperty ( index ) ;
279
289
@@ -283,8 +293,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
283
293
throw Error ( 'cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.' ) ;
284
294
}
285
295
286
- if ( this . _selectedIndex != newIndex &&
287
- ! this . _anyControlsInvalidOrPending ( newIndex ) &&
296
+ if ( this . _selectedIndex != newIndex && ! this . _anyControlsInvalidOrPending ( newIndex ) &&
288
297
( newIndex >= this . _selectedIndex || this . steps . toArray ( ) [ newIndex ] . editable ) ) {
289
298
this . _updateSelectedItemIndex ( index ) ;
290
299
}
@@ -305,20 +314,18 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
305
314
}
306
315
307
316
/** Event emitted when the selected step has changed. */
308
- @Output ( ) selectionChange : EventEmitter < StepperSelectionEvent >
309
- = new EventEmitter < StepperSelectionEvent > ( ) ;
317
+ @Output ( )
318
+ selectionChange : EventEmitter < StepperSelectionEvent > = new EventEmitter < StepperSelectionEvent > ( ) ;
310
319
311
320
/** Used to track unique ID for each stepper component. */
312
321
_groupId : number ;
313
322
314
323
protected _orientation : StepperOrientation = 'horizontal' ;
315
324
316
325
constructor (
317
- @Optional ( ) private _dir : Directionality ,
318
- private _changeDetectorRef : ChangeDetectorRef ,
319
- // @breaking -change 8.0.0 `_elementRef` and `_document` parameters to become required.
320
- private _elementRef ?: ElementRef < HTMLElement > ,
321
- @Inject ( DOCUMENT ) _document ?: any ) {
326
+ @Optional ( ) private _dir : Directionality , private _changeDetectorRef : ChangeDetectorRef ,
327
+ // @breaking -change 8.0.0 `_elementRef` and `_document` parameters to become required.
328
+ private _elementRef ?: ElementRef < HTMLElement > , @Inject ( DOCUMENT ) _document ?: any ) {
322
329
this . _groupId = nextId ++ ;
323
330
this . _document = _document ;
324
331
}
@@ -328,12 +335,12 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
328
335
// extend this one might have them as view chidren. We initialize the keyboard handling in
329
336
// AfterViewInit so we're guaranteed for both view and content children to be defined.
330
337
this . _keyManager = new FocusKeyManager < FocusableOption > ( this . _stepHeader )
331
- . withWrap ( )
332
- . withVerticalOrientation ( this . _orientation === 'vertical' ) ;
338
+ . withWrap ( )
339
+ . withVerticalOrientation ( this . _orientation === 'vertical' ) ;
333
340
334
- ( this . _dir ? this . _dir . change as Observable < Direction > : obaservableOf < Direction > ( ) )
335
- . pipe ( startWith ( this . _layoutDirection ( ) ) , takeUntil ( this . _destroyed ) )
336
- . subscribe ( direction => this . _keyManager . withHorizontalOrientation ( direction ) ) ;
341
+ ( this . _dir ? ( this . _dir . change as Observable < Direction > ) : obaservableOf < Direction > ( ) )
342
+ . pipe ( startWith ( this . _layoutDirection ( ) ) , takeUntil ( this . _destroyed ) )
343
+ . subscribe ( direction => this . _keyManager . withHorizontalOrientation ( direction ) ) ;
337
344
338
345
this . _keyManager . updateActiveItemIndex ( this . _selectedIndex ) ;
339
346
@@ -397,9 +404,8 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
397
404
const step = this . steps . toArray ( ) [ index ] ;
398
405
const isCurrentStep = this . _isCurrentStep ( index ) ;
399
406
400
- return step . _displayDefaultIndicatorType
401
- ? this . _getDefaultIndicatorLogic ( step , isCurrentStep )
402
- : this . _getGuidelineLogic ( step , isCurrentStep , state ) ;
407
+ return step . _displayDefaultIndicatorType ? this . _getDefaultIndicatorLogic ( step , isCurrentStep ) :
408
+ this . _getGuidelineLogic ( step , isCurrentStep , state ) ;
403
409
}
404
410
405
411
private _getDefaultIndicatorLogic ( step : CdkStep , isCurrentStep : boolean ) : StepState {
@@ -413,9 +419,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
413
419
}
414
420
415
421
private _getGuidelineLogic (
416
- step : CdkStep ,
417
- isCurrentStep : boolean ,
418
- state : StepState = STEP_STATE . NUMBER ) : StepState {
422
+ step : CdkStep , isCurrentStep : boolean , state : StepState = STEP_STATE . NUMBER ) : StepState {
419
423
if ( step . _showError && step . hasError && ! isCurrentStep ) {
420
424
return STEP_STATE . ERROR ;
421
425
} else if ( step . completed && ! isCurrentStep ) {
@@ -486,10 +490,9 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
486
490
if ( this . _linear && index >= 0 ) {
487
491
return steps . slice ( 0 , index ) . some ( step => {
488
492
const control = step . stepControl ;
489
- const isIncomplete = control ?
490
- ( control . invalid || control . pending || ! step . interacted ) :
491
- ! step . completed ;
492
- return isIncomplete && ! step . optional ;
493
+ const isIncomplete =
494
+ control ? ( control . invalid || control . pending || ! step . interacted ) : ! step . completed ;
495
+ return isIncomplete && ! step . optional && ! step . _completedOverride ;
493
496
} ) ;
494
497
}
495
498
0 commit comments