Skip to content

Commit

Permalink
fix(material-experimental/mdc-form-field): ensure appearance is valid (
Browse files Browse the repository at this point in the history
…#24963)

* fix(material-experimental/mdc-form-field): ensure appearance is valid

* fix(material-experimental/mdc-form-field): address feedback
  • Loading branch information
mmalerba authored Jun 1, 2022
1 parent 299b2f2 commit 7736515
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ export class MatFormField
}
set appearance(value: MatFormFieldAppearance) {
const oldValue = this._appearance;
this._appearance = value || this._defaults?.appearance || DEFAULT_APPEARANCE;
const newAppearance = value || this._defaults?.appearance || DEFAULT_APPEARANCE;
if (typeof ngDevMode === 'undefined' || ngDevMode) {
if (newAppearance !== 'fill' && newAppearance !== 'outline') {
throw new Error(
`MatFormField: Invalid appearance "${newAppearance}", valid values are "fill" or "outline".`,
);
}
}
this._appearance = newAppearance;
if (this._appearance === 'outline' && this._appearance !== oldValue) {
this._refreshOutlineNotchWidth();

Expand Down
2 changes: 1 addition & 1 deletion src/material/form-field/testing/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export function runHarnessTests(
<span matTextSuffix *ngIf="isMdc">suffix_text</span>
</mat-form-field>
<mat-form-field appearance="standard" color="warn" id="with-errors">
<mat-form-field [appearance]="isMdc ? 'fill' : 'standard'" color="warn" id="with-errors">
<span class="custom-control">Custom control harness</span>
<input matInput [formControl]="requiredControl">
Expand Down

0 comments on commit 7736515

Please sign in to comment.