Skip to content

Commit f9ef62c

Browse files
committed
fix(material-experimental/mdc-form-field): address feedback
1 parent f87d505 commit f9ef62c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,15 @@ export class MatFormField
211211
}
212212
set appearance(value: MatFormFieldAppearance) {
213213
const oldValue = this._appearance;
214-
this._appearance = ['fill', 'outline'].includes(value)
215-
? value
216-
: this._defaults?.appearance || DEFAULT_APPEARANCE;
214+
const newAppearance = value || this._defaults?.appearance || DEFAULT_APPEARANCE;
215+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
216+
if (newAppearance !== 'fill' && newAppearance !== 'outline') {
217+
throw new Error(
218+
`MatFormField: Invalid appearance "${newAppearance}", valid values are "fill" or "outline".`,
219+
);
220+
}
221+
}
222+
this._appearance = newAppearance;
217223
if (this._appearance === 'outline' && this._appearance !== oldValue) {
218224
this._refreshOutlineNotchWidth();
219225

src/material/form-field/testing/shared.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export function runHarnessTests(
266266
<span matTextSuffix *ngIf="isMdc">suffix_text</span>
267267
</mat-form-field>
268268
269-
<mat-form-field appearance="standard" color="warn" id="with-errors">
269+
<mat-form-field [appearance]="isMdc ? 'fill' : 'standard'" color="warn" id="with-errors">
270270
<span class="custom-control">Custom control harness</span>
271271
<input matInput [formControl]="requiredControl">
272272

0 commit comments

Comments
 (0)