Skip to content

Commit 75e191d

Browse files
authored
fix(material-experimental/mdc-form-field): use coercion for boolean input (#22194)
1 parent 6db0fa9 commit 75e191d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 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 {BooleanInput, 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,7 @@ 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?.hideRequiredMarker ?? false;
329333
}
330334

331335
ngAfterViewInit() {
@@ -718,4 +722,6 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
718722
// shadow DOM, however browser that support shadow DOM should support `getRootNode` as well.
719723
return document.documentElement!.contains(element);
720724
}
725+
726+
static ngAcceptInputType_hideRequiredMarker: BooleanInput;
721727
}

0 commit comments

Comments
 (0)