Skip to content

Commit 24e191a

Browse files
authored
fix(material/stepper): handle empty label in horizontal stepper (#31665)
Fixes that the horizontal stepper was leaving a blank space if the step's label is empty. Fixes #31655.
1 parent 78a93fb commit 24e191a

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

goldens/material/stepper/index.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export class MatStepHeader extends CdkStepHeader implements AfterViewInit, OnDes
8282
// (undocumented)
8383
_getDefaultTextForState(state: StepState): string;
8484
_getHostElement(): HTMLElement;
85+
// (undocumented)
86+
protected _hasEmptyLabel(): boolean;
87+
// (undocumented)
88+
protected _hasErrorLabel(): boolean;
89+
// (undocumented)
90+
protected _hasOptionalLabel(): boolean;
8591
iconOverrides: {
8692
[key: string]: TemplateRef<MatStepperIconContext>;
8793
};

src/material/stepper/step-header.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
<div class="mat-step-text-label">{{label}}</div>
4242
}
4343

44-
@if (optional && state != 'error') {
44+
@if (_hasOptionalLabel()) {
4545
<div class="mat-step-optional">{{_intl.optionalLabel}}</div>
4646
}
4747

48-
@if (state === 'error') {
48+
@if (_hasErrorLabel()) {
4949
<div class="mat-step-sub-label-error">{{errorMessage}}</div>
5050
}
5151
</div>

src/material/stepper/step-header.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ $fallbacks: m3-stepper.get-tokens();
143143
font-size: token-utils.slot(stepper-header-selected-state-label-text-size, $fallbacks);
144144
font-weight: token-utils.slot(stepper-header-selected-state-label-text-weight, $fallbacks);
145145
}
146+
147+
.mat-step-header-empty-label & {
148+
min-width: 0;
149+
}
146150
}
147151

148152
.mat-step-text-label {

src/material/stepper/step-header.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {_CdkPrivateStyleLoader, _VisuallyHiddenLoader} from '@angular/cdk/privat
3434
styleUrl: 'step-header.css',
3535
host: {
3636
'class': 'mat-step-header',
37+
'[class.mat-step-header-empty-label]': '_hasEmptyLabel()',
3738
'[class]': '"mat-" + (color || "primary")',
3839
'role': 'tab',
3940
},
@@ -140,4 +141,21 @@ export class MatStepHeader extends CdkStepHeader implements AfterViewInit, OnDes
140141
}
141142
return state;
142143
}
144+
145+
protected _hasEmptyLabel() {
146+
return (
147+
!this._stringLabel() &&
148+
!this._templateLabel() &&
149+
!this._hasOptionalLabel() &&
150+
!this._hasErrorLabel()
151+
);
152+
}
153+
154+
protected _hasOptionalLabel() {
155+
return this.optional && this.state !== 'error';
156+
}
157+
158+
protected _hasErrorLabel() {
159+
return this.state === 'error';
160+
}
143161
}

src/material/stepper/stepper.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ $fallbacks: m3-stepper.get-tokens();
8181
}
8282
}
8383

84+
&.mat-step-header-empty-label .mat-step-icon {
85+
margin: 0;
86+
}
87+
8488
$vertical-padding: _get-vertical-padding-calc();
8589

8690
&::before,

0 commit comments

Comments
 (0)