File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -297,8 +297,16 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
297
297
throw Error ( 'cdkStepper: Cannot assign out-of-bounds value to `selectedIndex`.' ) ;
298
298
}
299
299
300
+ const selectedStep = this . selected ;
301
+
302
+ if ( selectedStep ) {
303
+ // TODO: this should really be called something like `visited` instead. Just because
304
+ // the user has seen the step doesn't guarantee that they've interacted with it.
305
+ selectedStep . interacted = true ;
306
+ }
307
+
300
308
if ( this . _selectedIndex != newIndex && ! this . _anyControlsInvalidOrPending ( newIndex ) &&
301
- ( newIndex >= this . _selectedIndex || this . steps . toArray ( ) [ newIndex ] . editable ) ) {
309
+ ( newIndex >= this . _selectedIndex || this . _steps . toArray ( ) [ newIndex ] . editable ) ) {
302
310
this . _updateSelectedItemIndex ( index ) ;
303
311
}
304
312
} else {
@@ -487,12 +495,8 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
487
495
}
488
496
489
497
private _anyControlsInvalidOrPending ( index : number ) : boolean {
490
- const steps = this . steps . toArray ( ) ;
491
-
492
- steps [ this . _selectedIndex ] . interacted = true ;
493
-
494
498
if ( this . _linear && index >= 0 ) {
495
- return steps . slice ( 0 , index ) . some ( step => {
499
+ return this . steps . toArray ( ) . slice ( 0 , index ) . some ( step => {
496
500
const control = step . stepControl ;
497
501
const isIncomplete =
498
502
control ? ( control . invalid || control . pending || ! step . interacted ) : ! step . completed ;
Original file line number Diff line number Diff line change @@ -937,6 +937,28 @@ describe('MatStepper', () => {
937
937
938
938
expect ( headerRipples . every ( ripple => ripple . disabled ) ) . toBe ( true ) ;
939
939
} ) ;
940
+
941
+ it ( 'should be able to mark all steps as interacted' , ( ) => {
942
+ const fixture = createComponent ( SimpleMatHorizontalStepperApp ) ;
943
+ fixture . detectChanges ( ) ;
944
+
945
+ const stepper : MatStepper =
946
+ fixture . debugElement . query ( By . directive ( MatStepper ) ) . componentInstance ;
947
+
948
+ expect ( stepper . steps . map ( step => step . interacted ) ) . toEqual ( [ false , false , false ] ) ;
949
+
950
+ stepper . next ( ) ;
951
+ fixture . detectChanges ( ) ;
952
+ expect ( stepper . steps . map ( step => step . interacted ) ) . toEqual ( [ true , false , false ] ) ;
953
+
954
+ stepper . next ( ) ;
955
+ fixture . detectChanges ( ) ;
956
+ expect ( stepper . steps . map ( step => step . interacted ) ) . toEqual ( [ true , true , false ] ) ;
957
+
958
+ stepper . next ( ) ;
959
+ fixture . detectChanges ( ) ;
960
+ expect ( stepper . steps . map ( step => step . interacted ) ) . toEqual ( [ true , true , true ] ) ;
961
+ } ) ;
940
962
} ) ;
941
963
942
964
describe ( 'linear stepper with valid step' , ( ) => {
You can’t perform that action at this time.
0 commit comments