Skip to content

Commit 81b5bef

Browse files
committed
Fix(material/autocomplete): Enhanced offset determination by considering parent form field and appearance.
Fix #27476
1 parent c585fdd commit 81b5bef

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,13 @@ export class MatAutocompleteTrigger
831831
// border-radius based on the overlay position.
832832
const panelClass = this._aboveClass;
833833

834-
// Calculate vertical overlay offset with outline, or set to 0.
835-
const offsetY = this._formField?._getOverlayOffsetOutlined() || 0;
834+
/**
835+
* Calculate the vertical offset for the overlay when the input field has an outline appearance.
836+
* In the outline appearance, the overlay should have extra space to display the label correctly.
837+
*/
838+
const outlineHeight =
839+
this._formField?._floatingLabel?.element.getBoundingClientRect().height || 0;
840+
const offsetY = this._formField?._hasOutline() ? -outlineHeight / 2 : 0;
836841

837842
const abovePositions: ConnectedPosition[] = [
838843
{

src/material/form-field/form-field.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,6 @@ export class MatFormField
503503
return this.appearance === 'outline';
504504
}
505505

506-
/**
507-
* Calculate the vertical offset for the overlay when the input field has an outline appearance.
508-
* In the outline appearance, the overlay should have extra space to display the label correctly.
509-
* This function calculates the vertical offset needed.
510-
*/
511-
_getOverlayOffsetOutlined() {
512-
const outlineHeight = this._floatingLabel?.element.getBoundingClientRect().height || 0;
513-
return this._hasOutline() ? -outlineHeight / 2 : 0;
514-
}
515-
516506
/**
517507
* Whether the label should display in the infix. Labels in the outline appearance are
518508
* displayed as part of the notched-outline and are horizontally offset to account for

0 commit comments

Comments
 (0)