Skip to content

Commit

Permalink
fix(material-experimental/mdc-form-field): use coercion for boolean i…
Browse files Browse the repository at this point in the history
…nput (#22194)
  • Loading branch information
andrewseguin committed Mar 23, 2021
1 parent 6db0fa9 commit 75e191d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {MatFormFieldNotchedOutline} from './directives/notched-outline';
import {MAT_PREFIX, MatPrefix} from './directives/prefix';
import {MAT_SUFFIX, MatSuffix} from './directives/suffix';
import {DOCUMENT} from '@angular/common';
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';

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

/** Whether the required marker should be hidden. */
@Input() hideRequiredMarker: boolean = false;
@Input()
get hideRequiredMarker(): boolean { return this._hideRequiredMarker; }
set hideRequiredMarker(value: boolean) {
this._hideRequiredMarker = coerceBooleanProperty(value);
}
private _hideRequiredMarker: boolean;

/** The color palette for the form-field. */
@Input() color: ThemePalette = 'primary';
Expand Down Expand Up @@ -323,9 +329,7 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
this.appearance = _defaults.appearance;
}

if (_defaults && _defaults.hideRequiredMarker) {
this.hideRequiredMarker = true;
}
this._hideRequiredMarker = _defaults?.hideRequiredMarker ?? false;
}

ngAfterViewInit() {
Expand Down Expand Up @@ -718,4 +722,6 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
// shadow DOM, however browser that support shadow DOM should support `getRootNode` as well.
return document.documentElement!.contains(element);
}

static ngAcceptInputType_hideRequiredMarker: BooleanInput;
}

0 comments on commit 75e191d

Please sign in to comment.