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.
@@ -124,12 +124,7 @@ export class CdkStep implements OnChanges {
124
124
@ViewChild ( TemplateRef ) content : TemplateRef < any > ;
125
125
126
126
/** The top level abstract control of the step. */
127
- @Input ( ) stepControl : {
128
- valid : boolean ;
129
- invalid : boolean ;
130
- pending : boolean ;
131
- reset : ( ) => void ;
132
- } ;
127
+ @Input ( ) stepControl : { valid : boolean ; invalid : boolean ; pending : boolean ; reset : ( ) => void } ;
133
128
134
129
/** Whether user has seen the expanded step content or not. */
135
130
interacted = false ;
@@ -154,15 +149,19 @@ export class CdkStep implements OnChanges {
154
149
155
150
/** Whether the user can return to this step once it has been marked as completed. */
156
151
@Input ( )
157
- get editable ( ) : boolean { return this . _editable ; }
152
+ get editable ( ) : boolean {
153
+ return this . _editable ;
154
+ }
158
155
set editable ( value : boolean ) {
159
156
this . _editable = coerceBooleanProperty ( value ) ;
160
157
}
161
158
private _editable = true ;
162
159
163
160
/** Whether the completion of step is optional. */
164
161
@Input ( )
165
- get optional ( ) : boolean { return this . _optional ; }
162
+ get optional ( ) : boolean {
163
+ return this . _optional ;
164
+ }
166
165
set optional ( value : boolean ) {
167
166
this . _optional = coerceBooleanProperty ( value ) ;
168
167
}
@@ -171,12 +170,12 @@ export class CdkStep implements OnChanges {
171
170
/** Whether step is marked as completed. */
172
171
@Input ( )
173
172
get completed ( ) : boolean {
174
- return this . _customCompleted == null ? this . _getDefaultCompleted ( ) : this . _customCompleted ;
173
+ return this . _completedOverride == null ? this . _getDefaultCompleted ( ) : this . _completedOverride ;
175
174
}
176
175
set completed ( value : boolean ) {
177
- this . _customCompleted = coerceBooleanProperty ( value ) ;
176
+ this . _completedOverride = coerceBooleanProperty ( value ) ;
178
177
}
179
- private _customCompleted : boolean | null = null ;
178
+ _completedOverride : boolean | null = null ;
180
179
181
180
private _getDefaultCompleted ( ) {
182
181
return this . stepControl ? this . stepControl . valid && this . interacted : this . interacted ;
@@ -190,16 +189,16 @@ export class CdkStep implements OnChanges {
190
189
set hasError ( value : boolean ) {
191
190
this . _customError = coerceBooleanProperty ( value ) ;
192
191
}
193
- private _customError : boolean | null = null ;
192
+ private _customError : boolean | null = null ;
194
193
195
194
private _getDefaultError ( ) {
196
195
return this . stepControl && this . stepControl . invalid && this . interacted ;
197
196
}
198
197
199
198
/** @breaking -change 8.0.0 remove the `?` after `stepperOptions` */
200
199
constructor (
201
- @Inject ( forwardRef ( ( ) => CdkStepper ) ) private _stepper : CdkStepper ,
202
- @Optional ( ) @Inject ( STEPPER_GLOBAL_OPTIONS ) stepperOptions ?: StepperOptions ) {
200
+ @Inject ( forwardRef ( ( ) => CdkStepper ) ) private _stepper : CdkStepper ,
201
+ @Optional ( ) @Inject ( STEPPER_GLOBAL_OPTIONS ) stepperOptions ?: StepperOptions ) {
203
202
this . _stepperOptions = stepperOptions ? stepperOptions : { } ;
204
203
this . _displayDefaultIndicatorType = this . _stepperOptions . displayDefaultIndicatorType !== false ;
205
204
this . _showError = ! ! this . _stepperOptions . showError ;
@@ -214,8 +213,8 @@ export class CdkStep implements OnChanges {
214
213
reset ( ) : void {
215
214
this . interacted = false ;
216
215
217
- if ( this . _customCompleted != null ) {
218
- this . _customCompleted = false ;
216
+ if ( this . _completedOverride != null ) {
217
+ this . _completedOverride = false ;
219
218
}
220
219
221
220
if ( this . _customError != null ) {
@@ -249,7 +248,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
249
248
* @breaking -change 8.0.0 Remove `| undefined` once the `_document`
250
249
* constructor param is required.
251
250
*/
252
- private _document : Document | undefined ;
251
+ private _document : Document | undefined ;
253
252
254
253
/**
255
254
* The list of step components that the stepper is holding.
@@ -259,7 +258,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
259
258
@ContentChildren ( CdkStep ) _steps : QueryList < CdkStep > ;
260
259
261
260
/** The list of step components that the stepper is holding. */
262
- get steps ( ) : QueryList < CdkStep > {
261
+ get steps ( ) : QueryList < CdkStep > {
263
262
return this . _steps ;
264
263
}
265
264
@@ -272,13 +271,19 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
272
271
273
272
/** Whether the validity of previous steps should be checked or not. */
274
273
@Input ( )
275
- get linear ( ) : boolean { return this . _linear ; }
276
- 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
+ }
277
280
private _linear = false ;
278
281
279
282
/** The index of the selected step. */
280
283
@Input ( )
281
- get selectedIndex ( ) { return this . _selectedIndex ; }
284
+ get selectedIndex ( ) {
285
+ return this . _selectedIndex ;
286
+ }
282
287
set selectedIndex ( index : number ) {
283
288
const newIndex = coerceNumberProperty ( index ) ;
284
289
@@ -288,8 +293,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
288
293
throw Error ( 'cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.' ) ;
289
294
}
290
295
291
- if ( this . _selectedIndex != newIndex &&
292
- ! this . _anyControlsInvalidOrPending ( newIndex ) &&
296
+ if ( this . _selectedIndex != newIndex && ! this . _anyControlsInvalidOrPending ( newIndex ) &&
293
297
( newIndex >= this . _selectedIndex || this . steps . toArray ( ) [ newIndex ] . editable ) ) {
294
298
this . _updateSelectedItemIndex ( index ) ;
295
299
}
@@ -310,20 +314,18 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
310
314
}
311
315
312
316
/** Event emitted when the selected step has changed. */
313
- @Output ( ) selectionChange : EventEmitter < StepperSelectionEvent >
314
- = new EventEmitter < StepperSelectionEvent > ( ) ;
317
+ @Output ( )
318
+ selectionChange : EventEmitter < StepperSelectionEvent > = new EventEmitter < StepperSelectionEvent > ( ) ;
315
319
316
320
/** Used to track unique ID for each stepper component. */
317
321
_groupId : number ;
318
322
319
323
protected _orientation : StepperOrientation = 'horizontal' ;
320
324
321
325
constructor (
322
- @Optional ( ) private _dir : Directionality ,
323
- private _changeDetectorRef : ChangeDetectorRef ,
324
- // @breaking -change 8.0.0 `_elementRef` and `_document` parameters to become required.
325
- private _elementRef ?: ElementRef < HTMLElement > ,
326
- @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 ) {
327
329
this . _groupId = nextId ++ ;
328
330
this . _document = _document ;
329
331
}
@@ -333,12 +335,12 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
333
335
// extend this one might have them as view chidren. We initialize the keyboard handling in
334
336
// AfterViewInit so we're guaranteed for both view and content children to be defined.
335
337
this . _keyManager = new FocusKeyManager < FocusableOption > ( this . _stepHeader )
336
- . withWrap ( )
337
- . withVerticalOrientation ( this . _orientation === 'vertical' ) ;
338
+ . withWrap ( )
339
+ . withVerticalOrientation ( this . _orientation === 'vertical' ) ;
338
340
339
- ( this . _dir ? this . _dir . change as Observable < Direction > : obaservableOf < Direction > ( ) )
340
- . pipe ( startWith ( this . _layoutDirection ( ) ) , takeUntil ( this . _destroyed ) )
341
- . 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 ) ) ;
342
344
343
345
this . _keyManager . updateActiveItemIndex ( this . _selectedIndex ) ;
344
346
@@ -402,9 +404,8 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
402
404
const step = this . steps . toArray ( ) [ index ] ;
403
405
const isCurrentStep = this . _isCurrentStep ( index ) ;
404
406
405
- return step . _displayDefaultIndicatorType
406
- ? this . _getDefaultIndicatorLogic ( step , isCurrentStep )
407
- : this . _getGuidelineLogic ( step , isCurrentStep , state ) ;
407
+ return step . _displayDefaultIndicatorType ? this . _getDefaultIndicatorLogic ( step , isCurrentStep ) :
408
+ this . _getGuidelineLogic ( step , isCurrentStep , state ) ;
408
409
}
409
410
410
411
private _getDefaultIndicatorLogic ( step : CdkStep , isCurrentStep : boolean ) : StepState {
@@ -418,9 +419,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
418
419
}
419
420
420
421
private _getGuidelineLogic (
421
- step : CdkStep ,
422
- isCurrentStep : boolean ,
423
- state : StepState = STEP_STATE . NUMBER ) : StepState {
422
+ step : CdkStep , isCurrentStep : boolean , state : StepState = STEP_STATE . NUMBER ) : StepState {
424
423
if ( step . _showError && step . hasError && ! isCurrentStep ) {
425
424
return STEP_STATE . ERROR ;
426
425
} else if ( step . completed && ! isCurrentStep ) {
@@ -491,10 +490,9 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
491
490
if ( this . _linear && index >= 0 ) {
492
491
return steps . slice ( 0 , index ) . some ( step => {
493
492
const control = step . stepControl ;
494
- const isIncomplete = control ?
495
- ( control . invalid || control . pending || ! step . interacted ) :
496
- ! step . completed ;
497
- return isIncomplete && ! step . optional ;
493
+ const isIncomplete =
494
+ control ? ( control . invalid || control . pending || ! step . interacted ) : ! step . completed ;
495
+ return isIncomplete && ! step . optional && ! step . _completedOverride ;
498
496
} ) ;
499
497
}
500
498
0 commit comments