Skip to content

Commit d8935d1

Browse files
authored
fix(material-experimental/mdc-form-field): always check hideRequiredMarker (#22068)
* fix(material-experimental/mdc-form-field): always check hideRequiredMarker * fix(material-experimental/mdc-form-field): add test * fix(material-experimental/mdc-form-field): add test to legacy
1 parent e782118 commit d8935d1

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
314314
@Inject(DOCUMENT) private _document?: any) {
315315
if (_defaults && _defaults.appearance) {
316316
this.appearance = _defaults.appearance;
317-
} else if (_defaults && _defaults.hideRequiredMarker) {
317+
}
318+
319+
if (_defaults && _defaults.hideRequiredMarker) {
318320
this.hideRequiredMarker = true;
319321
}
320322
}

src/material-experimental/mdc-input/input.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,17 @@ describe('MatFormField default options', () => {
12741274
expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(false);
12751275
});
12761276

1277-
it('should be able to change the default value of hideRequiredMarker', () => {
1277+
it('should be able to change the default value of hideRequiredMarker and appearance', () => {
12781278
const fixture = createComponent(MatInputWithAppearance, [{
1279-
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {hideRequiredMarker: true}}
1279+
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {
1280+
hideRequiredMarker: true,
1281+
appearance: 'outline',
1282+
}}
12801283
]);
12811284

12821285
fixture.detectChanges();
12831286
expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(true);
1287+
expect(fixture.componentInstance.formField.appearance).toBe('outline');
12841288
});
12851289

12861290
});

src/material/input/input.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,13 +1703,17 @@ describe('MatFormField default options', () => {
17031703
expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(false);
17041704
});
17051705

1706-
it('should be able to change the default value of hideRequiredMarker', () => {
1706+
it('should be able to change the default value of hideRequiredMarker and appearance', () => {
17071707
const fixture = createComponent(MatInputWithAppearance, [{
1708-
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {hideRequiredMarker: true}}
1708+
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {
1709+
hideRequiredMarker: true,
1710+
appearance: 'outline',
1711+
}}
17091712
]);
17101713

17111714
fixture.detectChanges();
17121715
expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(true);
1716+
expect(fixture.componentInstance.formField.appearance).toBe('outline');
17131717
});
17141718

17151719
});

0 commit comments

Comments
 (0)