angular / angular/components

bug(MatFormField): getConnectedOverlayOrigin includes form field hint area

Offen
#27,967 1 Kommentar 3 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?

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

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

v14 (works w/ Legacy)

### Description

When migrating to the MDC-based components, the `getConnectedOverlayOrigin()` method on `MatFormField` now seems to point to the bottom of entire form field div (i.e. including the hint area) rather than the bottom edge of the input box. This makes it difficult to attach overlays to the bottom of custom form fields in a clean non-hacky way.

Basic example that demonstrates the problem:

1. Create a basic component that implements `MatFormFieldControl` (just directly copying the example [from the guide here](https://material.angular.io/guide/creating-a-custom-form-field-control) works for this).
2. Add a simple `mat-autocomplete` and wire it up to the input on the component.
3. Add a `MatAutocompleteOrigin` field to the component which points to the `MatFormField`'s `getConnectedOverlayOrigin()` (also may need to update this on ngOnInit to be safe).
4. Set the `matAutocompleteConnectedTo` in the template to the `MatAutocompleteOrigin` field.

Previously this would make the autocomplete overlay open lined up below the bottom edge of the form field, now there is an unsightly gap.

### Reproduction

StackBlitz link: https://stackblitz.com/edit/6vnpqz

Steps to reproduce:
1. Click the form field

### Expected Behavior

Attached overlay should appear directly below the form field's underline

### Actual Behavior

Attached overlay appears below the form field's hint area

### Environment

- Angular: 16.1.1
- CDK/Material: 16.2.9
- Browser(s): Chrome, Firefox
- Operating System (e.g. Windows, macOS, Ubuntu): Windows, Ubuntu

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der StackBlitz-Reproduktion und dem Einstiegspunkt MatFormField.getConnectedOverlayOrigin() unter Verwendung des in diesem Issue beschriebenen benutzerdefinierten MatFormFieldControl- und mat-autocomplete-Setups. Bestätige, dass das verbundene Overlay direkt unterhalb der Unterstreichung des Formularfelds statt unterhalb des Hinweisbereichs positioniert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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