Skip to content

Commit 286d3b5

Browse files
committed
refactor(form-field): allow AbstractControlDirective as MatFormFieldControl.ngControl
Allows for an `AbstractControlDirective` to be passed in as the `MatFormFieldControl.ngControl`. The advantage of passing in the abstract control directive is that it allows both form controls and form groups. This is necessary for the date range picker.
1 parent 4405429 commit 286d3b5

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Observable} from 'rxjs';
10-
import {NgControl} from '@angular/forms';
10+
import {NgControl, AbstractControlDirective} from '@angular/forms';
1111
import {Directive} from '@angular/core';
1212

1313

@@ -30,7 +30,7 @@ export abstract class MatFormFieldControl<T> {
3030
readonly placeholder: string;
3131

3232
/** Gets the NgControl for this control. */
33-
readonly ngControl: NgControl | null;
33+
readonly ngControl: NgControl | AbstractControlDirective | null;
3434

3535
/** Whether the control is focused. */
3636
readonly focused: boolean;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {MatPlaceholder} from './placeholder';
5050
import {MatPrefix} from './prefix';
5151
import {MatSuffix} from './suffix';
5252
import {Platform} from '@angular/cdk/platform';
53-
import {NgControl} from '@angular/forms';
53+
import {AbstractControlDirective} from '@angular/forms';
5454
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
5555

5656

@@ -383,7 +383,7 @@ export class MatFormField extends _MatFormFieldMixinBase
383383
}
384384

385385
/** Determines whether a class from the NgControl should be forwarded to the host element. */
386-
_shouldForward(prop: keyof NgControl): boolean {
386+
_shouldForward(prop: keyof AbstractControlDirective): boolean {
387387
const ngControl = this._control ? this._control.ngControl : null;
388388
return ngControl && ngControl[prop];
389389
}

tools/public_api_guard/material/form-field.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export declare class MatFormField extends _MatFormFieldMixinBase implements Afte
5353
_hasLabel(): boolean;
5454
_hasPlaceholder(): boolean;
5555
_hideControlPlaceholder(): boolean;
56-
_shouldForward(prop: keyof NgControl): boolean;
56+
_shouldForward(prop: keyof AbstractControlDirective): boolean;
5757
_shouldLabelFloat(): boolean;
5858
protected _validateControlChild(): void;
5959
getConnectedOverlayOrigin(): ElementRef;
@@ -81,7 +81,7 @@ export declare abstract class MatFormFieldControl<T> {
8181
readonly errorState: boolean;
8282
readonly focused: boolean;
8383
readonly id: string;
84-
readonly ngControl: NgControl | null;
84+
readonly ngControl: NgControl | AbstractControlDirective | null;
8585
readonly placeholder: string;
8686
readonly required: boolean;
8787
readonly shouldLabelFloat: boolean;

0 commit comments

Comments
 (0)