Skip to content

Commit

Permalink
fix(material-experimental/mdc-form-field): always check hideRequiredM…
Browse files Browse the repository at this point in the history
…arker (#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
  • Loading branch information
andrewseguin authored Mar 2, 2021
1 parent e782118 commit d8935d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/material-experimental/mdc-input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});
Expand Down
8 changes: 6 additions & 2 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});
Expand Down

0 comments on commit d8935d1

Please sign in to comment.