Skip to content

Commit c6f883c

Browse files
committed
fix(material/autocomplete): Optimized performance by first checking if the form field has an outline appearance.
Fix #27476
1 parent 81b5bef commit c6f883c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/material/autocomplete/autocomplete-trigger.ts

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

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;
834+
// Calculate the vertical offset for the overlay when the input field has an outline appearance.
835+
// In the outline appearance, the overlay should have extra space to display the label correctly.
836+
let offsetY = 0;
837+
if (this._formField?._hasOutline()) {
838+
offsetY = -(this._formField?._floatingLabel?.element.getBoundingClientRect().height || 0) / 2;
839+
}
841840

842841
const abovePositions: ConnectedPosition[] = [
843842
{

0 commit comments

Comments
 (0)