Skip to content

fix(material-experimental/mdc-form-field): use coercion for boolean input #22194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}