Skip to content

Commit 020edd5

Browse files
andrewseguinwagnermaciel
authored andcommitted
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 (cherry picked from commit d8935d1)
1 parent 901c58e commit 020edd5

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
@@ -313,7 +313,9 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
313313
@Inject(DOCUMENT) private _document?: any) {
314314
if (_defaults && _defaults.appearance) {
315315
this.appearance = _defaults.appearance;
316-
} else if (_defaults && _defaults.hideRequiredMarker) {
316+
}
317+
318+
if (_defaults && _defaults.hideRequiredMarker) {
317319
this.hideRequiredMarker = true;
318320
}
319321
}

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

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

1270-
it('should be able to change the default value of hideRequiredMarker', () => {
1270+
it('should be able to change the default value of hideRequiredMarker and appearance', () => {
12711271
const fixture = createComponent(MatInputWithAppearance, [{
1272-
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {hideRequiredMarker: true}}
1272+
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {
1273+
hideRequiredMarker: true,
1274+
appearance: 'outline',
1275+
}}
12731276
]);
12741277

12751278
fixture.detectChanges();
12761279
expect(fixture.componentInstance.formField.hideRequiredMarker).toBe(true);
1280+
expect(fixture.componentInstance.formField.appearance).toBe('outline');
12771281
});
12781282

12791283
});

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)