Skip to content

Commit 539ebf6

Browse files
crisbetojelbourn
authored andcommitted
fix(form-field): error in older versions of edge (#19698)
Some older versions of Edge will throw an error due to the way we were iterating over an `HTMLCollection`. This is actually something that TS throws a compilation error for, but we didn't catch it, because the variable was being inferred as `any`. Fixes #17810.
1 parent 2894a71 commit 539ebf6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export class MatFormField extends _MatFormFieldMixinBase
255255

256256
@ViewChild('connectionContainer', {static: true}) _connectionContainerRef: ElementRef;
257257
@ViewChild('inputContainer') _inputContainerRef: ElementRef;
258-
@ViewChild('label') private _label: ElementRef;
258+
@ViewChild('label') private _label: ElementRef<HTMLElement>;
259259

260260
@ContentChild(MatFormFieldControl) _controlNonStatic: MatFormFieldControl<any>;
261261
@ContentChild(MatFormFieldControl, {static: true}) _controlStatic: MatFormFieldControl<any>;
@@ -535,7 +535,7 @@ export class MatFormField extends _MatFormFieldMixinBase
535535
const labelEl = this._label ? this._label.nativeElement : null;
536536

537537
if (this.appearance !== 'outline' || !labelEl || !labelEl.children.length ||
538-
!labelEl.textContent.trim()) {
538+
!labelEl.textContent!.trim()) {
539539
return;
540540
}
541541

@@ -573,11 +573,12 @@ export class MatFormField extends _MatFormFieldMixinBase
573573
}
574574

575575
const containerStart = this._getStartEnd(containerRect);
576-
const labelStart = this._getStartEnd(labelEl.children[0].getBoundingClientRect());
576+
const labelChildren = labelEl.children;
577+
const labelStart = this._getStartEnd(labelChildren[0].getBoundingClientRect());
577578
let labelWidth = 0;
578579

579-
for (const child of labelEl.children) {
580-
labelWidth += child.offsetWidth;
580+
for (let i = 0; i < labelChildren.length; i++) {
581+
labelWidth += (labelChildren[i] as HTMLElement).offsetWidth;
581582
}
582583
startWidth = Math.abs(labelStart - containerStart) - outlineGapPadding;
583584
gapWidth = labelWidth > 0 ? labelWidth * floatingLabelScale + outlineGapPadding * 2 : 0;

0 commit comments

Comments
 (0)