diff --git a/src/material-experimental/mdc-form-field/form-field.ts b/src/material-experimental/mdc-form-field/form-field.ts index 3ef7684f4d1a..d4a4cd83006e 100644 --- a/src/material-experimental/mdc-form-field/form-field.ts +++ b/src/material-experimental/mdc-form-field/form-field.ts @@ -313,7 +313,9 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck @Inject(DOCUMENT) private _document?: any) { if (_defaults && _defaults.appearance) { this.appearance = _defaults.appearance; - } else if (_defaults && _defaults.hideRequiredMarker) { + } + + if (_defaults && _defaults.hideRequiredMarker) { this.hideRequiredMarker = true; } } diff --git a/src/material-experimental/mdc-input/input.spec.ts b/src/material-experimental/mdc-input/input.spec.ts index 19749729ee05..ba8123f970cc 100644 --- a/src/material-experimental/mdc-input/input.spec.ts +++ b/src/material-experimental/mdc-input/input.spec.ts @@ -1267,13 +1267,17 @@ describe('MatFormField default options', () => { expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(false); }); - it('should be able to change the default value of hideRequiredMarker', () => { + it('should be able to change the default value of hideRequiredMarker and appearance', () => { const fixture = createComponent(MatInputWithAppearance, [{ - provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {hideRequiredMarker: true}} + provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { + hideRequiredMarker: true, + appearance: 'outline', + }} ]); fixture.detectChanges(); expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(true); + expect(fixture.componentInstance.formField.appearance).toBe('outline'); }); }); diff --git a/src/material/input/input.spec.ts b/src/material/input/input.spec.ts index 6864c2012b34..9580b24f3cc5 100644 --- a/src/material/input/input.spec.ts +++ b/src/material/input/input.spec.ts @@ -1703,13 +1703,17 @@ describe('MatFormField default options', () => { expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(false); }); - it('should be able to change the default value of hideRequiredMarker', () => { + it('should be able to change the default value of hideRequiredMarker and appearance', () => { const fixture = createComponent(MatInputWithAppearance, [{ - provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {hideRequiredMarker: true}} + provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { + hideRequiredMarker: true, + appearance: 'outline', + }} ]); fixture.detectChanges(); expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(true); + expect(fixture.componentInstance.formField.appearance).toBe('outline'); }); });