@@ -53,6 +53,7 @@ import {MatFormFieldNotchedOutline} from './directives/notched-outline';
53
53
import { MAT_PREFIX , MatPrefix } from './directives/prefix' ;
54
54
import { MAT_SUFFIX , MatSuffix } from './directives/suffix' ;
55
55
import { DOCUMENT } from '@angular/common' ;
56
+ import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
56
57
57
58
/** Type for the available floatLabel values. */
58
59
export type FloatLabelType = 'always' | 'auto' ;
@@ -151,7 +152,12 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
151
152
@ContentChildren ( MatHint , { descendants : true } ) _hintChildren : QueryList < MatHint > ;
152
153
153
154
/** Whether the required marker should be hidden. */
154
- @Input ( ) hideRequiredMarker : boolean = false ;
155
+ @Input ( )
156
+ get hideRequiredMarker ( ) : boolean { return this . _hideRequiredMarker ; }
157
+ set hideRequiredMarker ( value : boolean ) {
158
+ this . _hideRequiredMarker = coerceBooleanProperty ( value ) ;
159
+ }
160
+ private _hideRequiredMarker : boolean ;
155
161
156
162
/** The color palette for the form-field. */
157
163
@Input ( ) color : ThemePalette = 'primary' ;
@@ -323,9 +329,7 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
323
329
this . appearance = _defaults . appearance ;
324
330
}
325
331
326
- if ( _defaults && _defaults . hideRequiredMarker ) {
327
- this . hideRequiredMarker = true ;
328
- }
332
+ this . _hideRequiredMarker = _defaults ?. hideRequiredMarker ?? false ;
329
333
}
330
334
331
335
ngAfterViewInit ( ) {
@@ -718,4 +722,6 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
718
722
// shadow DOM, however browser that support shadow DOM should support `getRootNode` as well.
719
723
return document . documentElement ! . contains ( element ) ;
720
724
}
725
+
726
+ static ngAcceptInputType_hideRequiredMarker : BooleanInput ;
721
727
}
0 commit comments