components icon indicating copy to clipboard operation
components copied to clipboard

The label on a mat form field with Outline with a prefix not aligning inside a dialog

Open abannsunny opened this issue 7 years ago • 31 comments

Bug:

Form-Field-Outline-Label-Gap does not reposition correctly when it is opened in a dialog and the Form-Field has a prefix.

This bug still exists in the latest version

there is an existing issue which is closed: https://github.com/angular/material2/issues/13769

image

What is the expected behavior? The Form-Field-Outline-Label-Gap should be positioned correctly with or without a prefix. Inside a dialog.

What is the current behavior? The Form-Field-Outline-Label-Gap does not reposition itself away from the form field prefix like the label does when it is opened in a dialog.

What are the steps to reproduce?

I edited the stackblitz https://stackblitz.com/edit/form-field-outline-label-gap-position-error-in-dialog

Which versions of Angular, Material, OS, TypeScript, browsers are affected? Angular 7.2.3 Angular Material 7.0.3 chrome: 71

abannsunny avatar Jan 30 '19 23:01 abannsunny

I noticed the same problem: Imgur

The problem occurs when I refresh page.

only Windows 8.1 (on the same version of Chrome in Ubuntu 18.04 don't occurs) Chrome 72.0.3626.119

kklimczak avatar Feb 25 '19 13:02 kklimczak

Same problem here

danbord avatar Feb 28 '19 13:02 danbord

Same problem:

image

lucasferreiralsf avatar Mar 15 '19 12:03 lucasferreiralsf

I encountered the same issue. It can be reproduced with the Dialog example form the official Angular Material website. Steps to reproduce

  1. Add appearance="outline" to "the mat-form-field" element
  2. Add <mat-icon matPrefix class="icon-prefix-padding">person</mat-icon> inside the "mat-form-field" element

image

If lazy, use this stackblitz :)

gazsiadam avatar Apr 01 '19 13:04 gazsiadam

@mmalerba is this addressed by one of the open form-field PRs?

jelbourn avatar May 12 '19 03:05 jelbourn

I don't think so, there's an open one for a similar issue with RTL (https://github.com/angular/components/pull/15415), but I don't think its related to this one

mmalerba avatar May 13 '19 16:05 mmalerba

When using embedded view from a prepared TemplateRef, the same issue appears

<ng-template #prefixRef>
  <button mat-icon-button *ngIf="switch">
    <mat-icon>check</mat-icon>
  </button>
  <mat-icon *ngIf="!switch">check</mat-icon>
</ng-template>

<p>
  <mat-form-field appearance="outline" floatLabel="always">
    <mat-label>Outline form field</mat-label>
    <ng-container matPrefix [ngTemplateOutlet]="prefixRef"></ng-container>
    <input matInput placeholder="Placeholder" />
    <mat-icon matSuffix>
      {{ switch ? 'sentiment_very_dissatisfied' : 'sentiment_satisfied' }}
    </mat-icon>
    <mat-hint>Weird behavior</mat-hint>
  </mat-form-field>
</p>

Example on stackblitz.com

ivibe avatar Nov 15 '19 17:11 ivibe

Seeing what I think may be the same issue here. The outline is initially correct, but when mobile device orientation is changed (e.g. landscape -> portrait), changing the width of the input, the outline will overlap the label text.

donmccurdy avatar Jun 01 '20 20:06 donmccurdy

Setting a fixed width globally on .mat-form-field-prefix is a temporary fix we are rolling with at the moment. The issue was visible when using a custom element with matPrefix even without a dialog in our case. Very situational, but figured I'd share.

raw3 avatar Jun 08 '20 13:06 raw3

Any update about this?

lsrsilva avatar Oct 08 '20 17:10 lsrsilva

Add reference to your mat field like #outlineFieldRef in mat-form-field tag

Then call this function based on your use case -> updateOutlineGap() Example: add focus in input field and call (focus)="outlineFieldRef.updateOutlineGap()"

shubhamseth29 avatar Nov 23 '20 08:11 shubhamseth29

any updates on this issue? I have the same problem, added a mat-icon in matPrefix for a mat-form-field with appearance="outline" everytime the label floats, it's pushed out of it's container. check screenshot I googled every possible solution, but i got nothing :(

farah111 avatar Dec 07 '20 16:12 farah111

@farah111 @abannsunny you can work around the problem using the fix provided by @shubhamseth29 above. Add the following to the DialogComponent in the stackblitz:

  @ViewChildren(MatFormField) formFields: QueryList<MatFormField>;

  ngAfterViewInit(): void {
    setTimeout(() => this.formFields.forEach(ff => ff.updateOutlineGap()), 100);
  }

gtranter avatar Dec 07 '20 17:12 gtranter

We have seen the same issue, are there any updates on when it would be fixed ?

Angular version: 10.1.0 Angular Material: 10.2.7

marlinverhulst avatar Feb 23 '21 11:02 marlinverhulst

@marlinverhulst facing the same issue here, and on the same versions. Anyone knows if this will be fixed in a future update of Angular Material theme?

Jackques avatar Feb 23 '21 11:02 Jackques

Same issue here using just a standard mat-input inside a mat-form-field...no prefix or suffix and the label aligns all the way to the left while the opening for it in the outline is near the center of the input. No styling applied at all...this is just out-of-the-box functionality. Definitely shouldn't have to rely on running something in a settimeout method to fix an issue. The material.angular.io website is displaying it correctly...not sure how they're doing that.

psenechal avatar Mar 09 '21 00:03 psenechal

Same issue here, just the default mat select. Please respond with a better solution than a timeout fix...

joedoublev98 avatar Mar 14 '21 13:03 joedoublev98

The baseline of all the text gets misaligned when using outline and prefixes, as well.

ghost avatar Apr 24 '21 22:04 ghost

Here is the screenshot on iPhone safari browser. Its misaligned on iPhone chrome as well.

Screenshot 2021-05-21 at 10 01 09 AM

It is working fine on web safari and chrome. Working fine on android chrome. The alignment with prefix is incorrect.

avinashkgit avatar May 21 '21 02:05 avinashkgit

@avinashkgit That seems to a completely different issue, not related to this one.

lundmikkel avatar May 21 '21 07:05 lundmikkel