angular / angular/components

bug(mat-form-field): mat-label incorrectly displayed at init (behavior possible)

Offen
#26,833 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/form-field P4
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

### Is this a regression?

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

### The previous version in which this bug was not present was

_No response_

### Description

Sometimes, when the component mat-form-field is initied too fastly, when we use mat-icon with the attribute matPrefix or matSuffix, the mat-label is misplaced only at the init of the entire component.

A possible behavior can be to initialize the mat-form-field with setTimeout at 100ms or more after the component loaded on ngOnInit().
But, when using ReactiveFormsModule, an error (NG01050: formControlName must be used with a parent formGroup directive) can still be present but the forms works **normally.**

### Reproduction

Steps to reproduce:
1. Create a mat-form-field
2. Add a mat-label to this one
3. Add a trailling mat-icon with matPrefix or matSuffix

### Expected Behavior

The mat-icon and mat-label must be placed normally, means the icon must be before the mat-label for example.

### Actual Behavior

The label must be placed after the icon for matSuffix but only at init he is misplaced above or below the mat-icon. The mat-label works normally after he is focused.

### Environment

- Angular: Angular 15.0.0
- CDK/Material: 15.2.2
- Browser(s): Brave, Edge
- Operating System (e.g. Windows, macOS, Ubuntu): Windows

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, den Initialisierungsfall mit Angular Material mat-form-field, mat-label, mat-icon und matPrefix oder matSuffix zu reproduzieren, einschließlich des beschriebenen ReactiveFormsModule-Szenarios. Untersuche die Initialisierung von mat-form-field und den Zeitpunkt von ngOnInit. Überprüfe anschließend, dass Icon und Label beim ersten Rendern korrekt positioniert sind, ohne den gemeldeten formControlName-Fehler.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
32/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.