From 86ed40c871909d76e5700eaa303e868350f8fcd8 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Thu, 30 Aug 2018 21:00:11 +0200 Subject: [PATCH] chore: fix compilation error in form field (#12907) Fixes a compilation error in the `matNativeControl` directive. --- src/lib/input/input.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lib/input/input.ts b/src/lib/input/input.ts index abf1aa7b985..8138f5517d8 100644 --- a/src/lib/input/input.ts +++ b/src/lib/input/input.ts @@ -185,7 +185,7 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl< // input element. To ensure that bindings for `type` work, we need to sync the setter // with the native property. Textarea elements don't support the type property or attribute. if (!this._isTextarea() && getSupportedInputTypes().has(this._type)) { - this._elementRef.nativeElement.type = this._type; + (this._elementRef.nativeElement as HTMLInputElement).type = this._type; } } protected _type = 'text'; @@ -221,16 +221,17 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl< 'week' ].filter(t => getSupportedInputTypes().has(t)); - constructor(protected _elementRef: ElementRef, - protected _platform: Platform, - /** @docs-private */ - @Optional() @Self() public ngControl: NgControl, - @Optional() _parentForm: NgForm, - @Optional() _parentFormGroup: FormGroupDirective, - _defaultErrorStateMatcher: ErrorStateMatcher, - @Optional() @Self() @Inject(MAT_INPUT_VALUE_ACCESSOR) inputValueAccessor: any, - private _autofillMonitor: AutofillMonitor, - ngZone: NgZone) { + constructor( + protected _elementRef: ElementRef, + protected _platform: Platform, + /** @docs-private */ + @Optional() @Self() public ngControl: NgControl, + @Optional() _parentForm: NgForm, + @Optional() _parentFormGroup: FormGroupDirective, + _defaultErrorStateMatcher: ErrorStateMatcher, + @Optional() @Self() @Inject(MAT_INPUT_VALUE_ACCESSOR) inputValueAccessor: any, + private _autofillMonitor: AutofillMonitor, + ngZone: NgZone) { super(_defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl); // If no input value accessor was explicitly specified, use the element as the input value // accessor. @@ -372,8 +373,9 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl< // For a single-selection ``, the label *always* floats to avoid // overlapping the label with the options. - const selectElement = this._elementRef.nativeElement; - return selectElement.multiple || !this.empty || selectElement.options[0].label || + const selectElement = this._elementRef.nativeElement as HTMLSelectElement; + + return selectElement.multiple || !this.empty || !!selectElement.options[0].label || this.focused; } else { return this.focused || !this.empty;