You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for your clarification. Please check through my reasoning below.
Could we simply just remove the padding space?
// MatFormFieldNotchedOutline_setNotchWidth(labelWidth: number){constnotch=this._notch.nativeElement;if(!this.open||!labelWidth){notch.style.width='';notch.style.paddingRight='0px';// <------------------ Remove padding-right: 8px that produce the space}else{
...
}}
Yes, it will have. The reason why the mat-label is empty is because Im creating a custom component that wraps the mat-form-field. The custom component can be configured (using input - labelAboveField) to control whether we want to display the label on top of the field or remains the default behavior. However, this implementation will cause the space issue.
<divstyle="display: flex; flex-direction: column;">
@if(labelAboveField()) {
<mat-labelstyle="padding: 4px 16px;">Some Label</mat-label>
}
<mat-form-field><mat-label><!-- The will produce the extra space -->
@if(!labelAboveField()) { Some Label }
</mat-label><mat-select></mat-select></mat-form-field></div>
If I using this approach, my code will be as following:
<divstyle="display: flex; flex-direction: column;">
@if(labelAboveField()) {
<mat-labelstyle="padding: 4px 16px;">Some Label</mat-label>
}
<mat-form-field>
@if(!labelAboveField()) {
<mat-label>Some Label</mat-label><!-- The will cause the mat-label not being displayed, due to display:none is being set -->
}
<mat-select></mat-select></mat-form-field></div>
This will cause the label will not be rendered if [labelAboveField]="true" by default. The labelAboveField value might be changed in runtime. I suspect this is due to the MatFormFieldNotchedOutline.ngAfterViewInit() will only run once. If it cannot find any mat-label, it will be assigned with mdc-notched-outline--no-label which will set display:none to the element forever.
Uh oh!
There was an error while loading. Please reload this page.
Is this a regression?
The previous version in which this bug was not present was
No response
Description
Extra space in Outline MatFormField Notch when the width of the label is 0.
Reproduction
StackBlitz link: https://stackblitz.com/edit/components-issue-starter-otgsx4ue?file=src%2Fmain.ts
Expected Behavior
The extra space (padding-right: 8px) SHOULD BE REMOVED if the label content is empty, when
The padding-right is being set by following css class:
.mdc-notched-outline--notched .mdc-notched-outline__notch
Actual Behavior
The extra space (padding-right: 8px) is VISIBLE despite the label content is empty, when
Environment
Angular CLI: 19.2.2
Node: 18.20.4
Package Manager: yarn 4.4.1
OS: win32 x64
Angular: 19.2.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.1902.2
@angular-devkit/build-angular 19.2.2
@angular-devkit/core 19.2.2
@angular-devkit/schematics 19.2.2
@angular/cdk 19.2.3
@angular/material 19.2.3
@schematics/angular 19.2.2
ng-packagr 19.2.0
rxjs 7.8.1
typescript 5.6.3
zone.js 0.15.0
The text was updated successfully, but these errors were encountered: