components icon indicating copy to clipboard operation
components copied to clipboard

Label for mat-form-field is overlapping with mat-icon in mat-tab.

Open simpleplayer opened this issue 1 year ago • 14 comments

Is this a regression?

  • [X] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

14

Description

Label is overlapping with icon.

  • When using in 2nd Tab of Tabgroup, surrounded with a e.g. a div, p, ...
  • and
  • When using the the mat-form-field with appearance "outline" and an icon with matPrefix.
<div>
            <mat-form-field appearance="outline">
                <mat-label>Outline form field</mat-label>
                <input matInput placeholder="Placeholder">
                <mat-icon matPrefix>sentiment_very_satisfied</mat-icon>
                <mat-hint>Hint</mat-hint>
            </mat-form-field>
        </div>

Reproduction

Steps to reproduce:

  1. add to app.module import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatTabsModule } from '@angular/material/tabs';

  2. add to app.component

<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="start">
    <mat-tab label="First">
        <div>
            <mat-form-field appearance="outline">
                <mat-label>Outline form field</mat-label>
                <input matInput placeholder="Placeholder">
                <mat-icon matPrefix>sentiment_very_satisfied</mat-icon>
                <mat-hint>Hint</mat-hint>
            </mat-form-field>
        </div>
    </mat-tab>
    <mat-tab label="Second">
        <div>
            <mat-form-field appearance="outline">
                <mat-label>Outline form field</mat-label>
                <input matInput placeholder="Placeholder">
                <mat-icon matPrefix>sentiment_very_satisfied</mat-icon>
                <mat-hint>Hint</mat-hint>
            </mat-form-field>
        </div>
    </mat-tab>
</mat-tab-group>#

for the input field in 2nd tab : label is overlapping with mat-icon 4. when inspecting the style, it seems the X transform is not correct

tabs

Expected Behavior

Label should have correct margin

Actual Behavior

Label is overlapping with mat-icon

Environment

  • Angular:15.0.0
  • CDK/Material:15.1.0
  • Browser(s):Chrome, Edge
  • Operating System (e.g. Windows, macOS, Ubuntu):Windows 10

simpleplayer avatar Jan 13 '23 13:01 simpleplayer

+1, encountering this issue as well while upgrading to angular@15 (from angular@14), temporary workaround I found is using lazy-loaded tabs makes the form input prefix text render as expected

<mat-tab label="Example Tab">
    <ng-template matTabContent>
        <app-example-tab></app-example-tab>
    </ng-template>
</mat-tab>

trentprynn avatar Jan 18 '23 20:01 trentprynn

👍 Still an issue. Encoutered during angular 15 upgrade as well.

the workaround that @trentprynn posted seems to get things to display correctly. Here is a stackblitz that reporudces the issue: https://stackblitz.com/edit/angular-b6q6sv-tyk3ag?file=src%2Fapp%2Fform-field-appearance-example.html,src%2Fapp%2Fform-field-appearance-example.ts

shaylanger avatar Feb 27 '23 22:02 shaylanger

This problem persisting in Angular Material version: 15.2.2 with Angular 15.2.2

The solution that @trentprynn not working for me. I use ng-container with ngTemplateOutlet for render my ng-template:

<mat-tab-group>
    <mat-tab label="Controle">
        <ng-container *ngTemplateOutlet="tableControle"></ng-container>
    </mat-tab>
    <mat-tab label="Revisões">
        <ng-container *ngTemplateOutlet="tableRevisao"></ng-container>
    </mat-tab>
</mat-tab-group>

<ng-template matTabContent #tableControle>
    <!--  content -->
</ng-template>

<ng-template matTabContent #tableRevisao>
   <!--  content -->
</ng-template>

thomasErich135 avatar Mar 11 '23 12:03 thomasErich135

As @thomasErich135 mentioned, the issue persists on Angular 15.2.2

Me and my team encountered the exact same issue described by OP. As @trentprynn suggested, lazy loading works. This workaround is not suitable for some cases in our application.

Nevac avatar Mar 16 '23 12:03 Nevac

+1

JanesH64 avatar Apr 18 '23 10:04 JanesH64

+1

mte-bad avatar Apr 19 '23 10:04 mte-bad

I also encountered a problem where the mat icon in a 'mat-form-filed' is overlapping with the 'mat-label', causing a visual issue.

Steps to reproduce

  1. Add a 'mat-form-filed' to a card.
  2. Place an icon as prefix within the 'mat-form-field'
  3. Add a 'mat-label to the 'mat-form-field'.
Screenshot 2023-05-26 at 9 11 58 PM

spp125 avatar May 27 '23 01:05 spp125

As @spp125 mentioned, the issue with the prefix icon persists on Angular 16.1.0 (material 16.1.3)....

Does anyone have a solution/workaround to this problem?

marcus-coube avatar Aug 10 '23 15:08 marcus-coube

We are facing overlapping labels when using prefix icons in inputs with appearance outline. This happens even outside of tabs or cards. image This only happens right after loading the page. When going forth and back using the normal angular routing the prefix icons/labels are displayed correct. I guess its something with const iconPrefixContainer = this._iconPrefixContainer?.nativeElement; const textPrefixContainer = this._textPrefixContainer?.nativeElement; const iconPrefixContainerWidth = iconPrefixContainer?.getBoundingClientRect().width ?? 0; const textPrefixContainerWidth = textPrefixContainer?.getBoundingClientRect().width ?? 0; in https://github.com/angular/components/blob/ccff68ccf69aff7a0b120819a6ceef7e8e2e7791/src/material/form-field/form-field.ts#L655 Still do not have any solution for it.

tdahlhoff avatar Sep 22 '23 10:09 tdahlhoff

Is it fixed in latest version?

therrax avatar Oct 27 '23 11:10 therrax

Hello, still having the issue on version 16.2.7

AzarielUr avatar Nov 17 '23 10:11 AzarielUr

Persists on Angular 17.0.2

userhv avatar Dec 11 '23 12:12 userhv

Same problem in 17.1.1. The lazy load seem to be a workaround for now.

e-karlsson avatar Jan 30 '24 07:01 e-karlsson

For me, the problem was that the icon comes from the network and its size is not known until it is loaded.

So when the form field is rendered initially, it doesn't know that my icon is 24x24 since it's not loaded yet. So the code pointed out by @tdahlhoff would find the width of the icon container to be 0.

Then when you come back, things look good, because the image is already loaded and cached, so the size is already known.

My workaround for this was to hardcode the size of my icon in the CSS.

kevindqc avatar Apr 17 '24 17:04 kevindqc