Skip to content

Commit 54bab8e

Browse files
committed
refactor(material/stepper): update code to use ng-container
Updates previous fix to use an ng-template instead of using mat-step-header twice.
1 parent ed990d5 commit 54bab8e

File tree

1 file changed

+37
-48
lines changed

1 file changed

+37
-48
lines changed

src/material/stepper/stepper.html

+37-48
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,9 @@
1313
<div class="mat-horizontal-stepper-wrapper">
1414
<div class="mat-horizontal-stepper-header-container" role="tablist">
1515
@for (step of steps; track step) {
16-
<mat-step-header
17-
class="mat-horizontal-stepper-header"
18-
role="tab"
19-
(click)="step.select()"
20-
(keydown)="_onKeydown($event)"
21-
[tabIndex]="_getFocusIndex() === $index ? 0 : -1"
22-
[id]="_getStepLabelId($index)"
23-
[attr.aria-posinset]="$index + 1"
24-
[attr.aria-setsize]="steps.length"
25-
[attr.aria-controls]="_getStepContentId($index)"
26-
[attr.aria-owns]="_getStepContentId($index)"
27-
[attr.aria-selected]="selectedIndex == $index"
28-
[attr.aria-label]="step.ariaLabel || null"
29-
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
30-
[attr.aria-disabled]="_stepIsNavigable($index, step) ? null : true"
31-
[index]="$index"
32-
[state]="_getIndicatorType($index, step.state)"
33-
[label]="step.stepLabel || step.label"
34-
[selected]="selectedIndex === $index"
35-
[active]="_stepIsNavigable($index, step)"
36-
[optional]="step.optional"
37-
[errorMessage]="step.errorMessage"
38-
[iconOverrides]="_iconOverrides"
39-
[disableRipple]="disableRipple || !_stepIsNavigable($index, step)"
40-
[color]="step.color || color"/>
16+
<ng-container
17+
[ngTemplateOutlet]="stepTemplate"
18+
[ngTemplateOutletContext]="{step, i: $index}"/>
4119
@if (!$last) {
4220
<div class="mat-stepper-horizontal-line"></div>
4321
}
@@ -65,29 +43,9 @@
6543
<div class="mat-vertical-stepper-wrapper" role="group">
6644
@for (step of steps; track step) {
6745
<div class="mat-step">
68-
<mat-step-header
69-
class="mat-vertical-stepper-header"
70-
role="button"
71-
(click)="step.select()"
72-
(keydown)="_onKeydown($event)"
73-
[tabIndex]="_getFocusIndex() === $index ? 0 : -1"
74-
[id]="_getStepLabelId($index)"
75-
[attr.aria-expanded]="selectedIndex === $index"
76-
[attr.aria-controls]="_getStepContentId($index)"
77-
[attr.aria-current]="selectedIndex == $index"
78-
[attr.aria-label]="step.ariaLabel || null"
79-
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
80-
[attr.aria-disabled]="_stepIsNavigable($index, step) ? null : true"
81-
[index]="$index"
82-
[state]="_getIndicatorType($index, step.state)"
83-
[label]="step.stepLabel || step.label"
84-
[selected]="selectedIndex === $index"
85-
[active]="_stepIsNavigable($index, step)"
86-
[optional]="step.optional"
87-
[errorMessage]="step.errorMessage"
88-
[iconOverrides]="_iconOverrides"
89-
[disableRipple]="disableRipple || !_stepIsNavigable($index, step)"
90-
[color]="step.color || color"/>
46+
<ng-container
47+
[ngTemplateOutlet]="stepTemplate"
48+
[ngTemplateOutletContext]="{step, i: $index}"/>
9149
<div
9250
#animatedContainer
9351
class="mat-vertical-content-container"
@@ -108,3 +66,34 @@
10866
</div>
10967
}
11068
}
69+
70+
<!-- Common step templating -->
71+
<ng-template let-step="step" let-i="i" #stepTemplate>
72+
<mat-step-header
73+
[class.mat-horizontal-stepper-header]="orientation === 'horizontal'"
74+
[class.mat-vertical-stepper-header]="orientation === 'vertical'"
75+
[attr.role]="orientation === 'horizontal'? 'tab' : 'button'"
76+
(click)="step.select()"
77+
(keydown)="_onKeydown($event)"
78+
[tabIndex]="_getFocusIndex() === i ? 0 : -1"
79+
[id]="_getStepLabelId(i)"
80+
[attr.aria-posinset]="orientation === 'horizontal'? i + 1 : undefined"
81+
[attr.aria-setsize]="orientation === 'horizontal'? steps.length : undefined"
82+
[attr.aria-controls]="_getStepContentId(i)"
83+
[attr.aria-selected]="orientation === 'horizontal' ? selectedIndex == i : undefined"
84+
[attr.aria-expanded]="orientation === 'vertical' ? selectedIndex == i : undefined"
85+
[attr.aria-label]="step.ariaLabel || null"
86+
[attr.aria-labelledby]="(!step.ariaLabel && step.ariaLabelledby) ? step.ariaLabelledby : null"
87+
[attr.aria-disabled]="_stepIsNavigable(i, step) ? null : true"
88+
[attr.aria-owns]="_getStepContentId(i)"
89+
[index]="i"
90+
[state]="_getIndicatorType(i, step.state)"
91+
[label]="step.stepLabel || step.label"
92+
[selected]="selectedIndex === i"
93+
[active]="_stepIsNavigable(i, step)"
94+
[optional]="step.optional"
95+
[errorMessage]="step.errorMessage"
96+
[iconOverrides]="_iconOverrides"
97+
[disableRipple]="disableRipple || !_stepIsNavigable(i, step)"
98+
[color]="step.color || color"/>
99+
</ng-template>

0 commit comments

Comments
 (0)