diff --git a/src/material-experimental/mdc-form-field/form-field.ts b/src/material-experimental/mdc-form-field/form-field.ts index 8b70cae3c8cf..63ee64665b0d 100644 --- a/src/material-experimental/mdc-form-field/form-field.ts +++ b/src/material-experimental/mdc-form-field/form-field.ts @@ -314,7 +314,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 298d014b370c..60a4031acd96 100644 --- a/src/material-experimental/mdc-input/input.spec.ts +++ b/src/material-experimental/mdc-input/input.spec.ts @@ -1274,13 +1274,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'); }); });