Skip to content

Commit cd7d8c8

Browse files
crisbetommalerba
authored andcommitted
fix(stepper): not rendering correctly in some cases when step… (#17555)
Fixes an issue where, in some cases, the stepper will stop picking up steps if one of the steps is wrapped in an `ngIf`.
1 parent c08050d commit cd7d8c8

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/material/stepper/stepper.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,18 @@ describe('MatStepper', () => {
11751175
});
11761176

11771177
});
1178+
1179+
it('should be able to toggle steps via ngIf', () => {
1180+
const fixture = createComponent(StepperWithNgIf);
1181+
fixture.detectChanges();
1182+
1183+
expect(fixture.nativeElement.querySelectorAll('.mat-step-header').length).toBe(1);
1184+
1185+
fixture.componentInstance.showStep2 = true;
1186+
fixture.detectChanges();
1187+
1188+
expect(fixture.nativeElement.querySelectorAll('.mat-step-header').length).toBe(2);
1189+
});
11781190
});
11791191

11801192
/** Asserts that keyboard interaction works correctly. */
@@ -1644,3 +1656,21 @@ class StepperWithAriaInputs {
16441656
})
16451657
class StepperWithIndirectDescendantSteps {
16461658
}
1659+
1660+
1661+
@Component({
1662+
template: `
1663+
<mat-vertical-stepper>
1664+
<mat-step>
1665+
<ng-template matStepLabel>Step 1</ng-template>
1666+
</mat-step>
1667+
1668+
<mat-step *ngIf="showStep2">
1669+
<ng-template matStepLabel>Step 2</ng-template>
1670+
</mat-step>
1671+
</mat-vertical-stepper>
1672+
`
1673+
})
1674+
class StepperWithNgIf {
1675+
showStep2 = false;
1676+
}

src/material/stepper/stepper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ import {MatStepperIcon, MatStepperIconContext} from './stepper-icon';
5151
moduleId: module.id,
5252
selector: 'mat-step',
5353
templateUrl: 'step.html',
54-
providers: [{provide: ErrorStateMatcher, useExisting: MatStep}],
54+
providers: [
55+
{provide: ErrorStateMatcher, useExisting: MatStep},
56+
{provide: CdkStep, useExisting: MatStep},
57+
],
5558
encapsulation: ViewEncapsulation.None,
5659
exportAs: 'matStep',
5760
changeDetection: ChangeDetectionStrategy.OnPush,

0 commit comments

Comments
 (0)