Skip to content

Commit 86ed40c

Browse files
crisbetojelbourn
authored andcommitted
chore: fix compilation error in form field (#12907)
Fixes a compilation error in the `matNativeControl` directive.
1 parent ac8ed31 commit 86ed40c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/lib/input/input.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
185185
// input element. To ensure that bindings for `type` work, we need to sync the setter
186186
// with the native property. Textarea elements don't support the type property or attribute.
187187
if (!this._isTextarea() && getSupportedInputTypes().has(this._type)) {
188-
this._elementRef.nativeElement.type = this._type;
188+
(this._elementRef.nativeElement as HTMLInputElement).type = this._type;
189189
}
190190
}
191191
protected _type = 'text';
@@ -221,16 +221,17 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
221221
'week'
222222
].filter(t => getSupportedInputTypes().has(t));
223223

224-
constructor(protected _elementRef: ElementRef<HTMLInputElement>,
225-
protected _platform: Platform,
226-
/** @docs-private */
227-
@Optional() @Self() public ngControl: NgControl,
228-
@Optional() _parentForm: NgForm,
229-
@Optional() _parentFormGroup: FormGroupDirective,
230-
_defaultErrorStateMatcher: ErrorStateMatcher,
231-
@Optional() @Self() @Inject(MAT_INPUT_VALUE_ACCESSOR) inputValueAccessor: any,
232-
private _autofillMonitor: AutofillMonitor,
233-
ngZone: NgZone) {
224+
constructor(
225+
protected _elementRef: ElementRef<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>,
226+
protected _platform: Platform,
227+
/** @docs-private */
228+
@Optional() @Self() public ngControl: NgControl,
229+
@Optional() _parentForm: NgForm,
230+
@Optional() _parentFormGroup: FormGroupDirective,
231+
_defaultErrorStateMatcher: ErrorStateMatcher,
232+
@Optional() @Self() @Inject(MAT_INPUT_VALUE_ACCESSOR) inputValueAccessor: any,
233+
private _autofillMonitor: AutofillMonitor,
234+
ngZone: NgZone) {
234235
super(_defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl);
235236
// If no input value accessor was explicitly specified, use the element as the input value
236237
// accessor.
@@ -372,8 +373,9 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
372373
// For a single-selection `<select>`, the label should float when the selected option has
373374
// a non-empty display value. For a `<select multiple>`, the label *always* floats to avoid
374375
// overlapping the label with the options.
375-
const selectElement = this._elementRef.nativeElement;
376-
return selectElement.multiple || !this.empty || selectElement.options[0].label ||
376+
const selectElement = this._elementRef.nativeElement as HTMLSelectElement;
377+
378+
return selectElement.multiple || !this.empty || !!selectElement.options[0].label ||
377379
this.focused;
378380
} else {
379381
return this.focused || !this.empty;

0 commit comments

Comments
 (0)