File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,12 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
244
244
. subscribe ( direction => this . _keyManager . withHorizontalOrientation ( direction ) ) ;
245
245
246
246
this . _keyManager . updateActiveItemIndex ( this . _selectedIndex ) ;
247
+
248
+ this . _steps . changes . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => {
249
+ if ( ! this . selected ) {
250
+ this . _selectedIndex = Math . max ( this . _selectedIndex - 1 , 0 ) ;
251
+ }
252
+ } ) ;
247
253
}
248
254
249
255
ngOnDestroy ( ) {
Original file line number Diff line number Diff line change @@ -388,6 +388,24 @@ describe('MatStepper', () => {
388
388
expect ( headers . every ( header => header . getAttribute ( 'aria-setsize' ) === '3' ) ) . toBe ( true ) ;
389
389
} ) ;
390
390
391
+ it ( 'should adjust the index when removing a step before the current one' , ( ) => {
392
+ const stepperComponent : MatVerticalStepper = fixture . debugElement
393
+ . query ( By . css ( 'mat-vertical-stepper' ) ) . componentInstance ;
394
+
395
+ stepperComponent . selectedIndex = 2 ;
396
+ fixture . detectChanges ( ) ;
397
+
398
+ // Re-assert since the setter has some extra logic.
399
+ expect ( stepperComponent . selectedIndex ) . toBe ( 2 ) ;
400
+
401
+ expect ( ( ) => {
402
+ fixture . componentInstance . showStepTwo = false ;
403
+ fixture . detectChanges ( ) ;
404
+ } ) . not . toThrow ( ) ;
405
+
406
+ expect ( stepperComponent . selectedIndex ) . toBe ( 1 ) ;
407
+ } ) ;
408
+
391
409
} ) ;
392
410
393
411
describe ( 'icon overrides' , ( ) => {
@@ -1038,7 +1056,7 @@ class SimpleMatHorizontalStepperApp {
1038
1056
<button mat-button matStepperNext>Next</button>
1039
1057
</div>
1040
1058
</mat-step>
1041
- <mat-step>
1059
+ <mat-step *ngIf="showStepTwo" >
1042
1060
<ng-template matStepLabel>Step 2</ng-template>
1043
1061
Content 2
1044
1062
<div>
@@ -1058,6 +1076,7 @@ class SimpleMatHorizontalStepperApp {
1058
1076
} )
1059
1077
class SimpleMatVerticalStepperApp {
1060
1078
inputLabel = 'Step 3' ;
1079
+ showStepTwo = true ;
1061
1080
}
1062
1081
1063
1082
@Component ( {
You can’t perform that action at this time.
0 commit comments