Skip to content

Commit 48ff297

Browse files
committed
fix(material-experimental/mdc-form-field): use coercion for boolean input
1 parent 8a10451 commit 48ff297

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {MatFormFieldNotchedOutline} from './directives/notched-outline';
5353
import {MAT_PREFIX, MatPrefix} from './directives/prefix';
5454
import {MAT_SUFFIX, MatSuffix} from './directives/suffix';
5555
import {DOCUMENT} from '@angular/common';
56+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
5657

5758
/** Type for the available floatLabel values. */
5859
export type FloatLabelType = 'always' | 'auto';
@@ -151,7 +152,12 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
151152
@ContentChildren(MatHint, {descendants: true}) _hintChildren: QueryList<MatHint>;
152153

153154
/** 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;
155161

156162
/** The color palette for the form-field. */
157163
@Input() color: ThemePalette = 'primary';
@@ -323,9 +329,8 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
323329
this.appearance = _defaults.appearance;
324330
}
325331

326-
if (_defaults && _defaults.hideRequiredMarker) {
327-
this.hideRequiredMarker = true;
328-
}
332+
this._hideRequiredMarker = (_defaults && _defaults.hideRequiredMarker != null) ?
333+
_defaults.hideRequiredMarker : false;
329334
}
330335

331336
ngAfterViewInit() {

0 commit comments

Comments
 (0)