Skip to content

Commit

Permalink
fix(material-experimental/mdc-form-field): Properly handle when defau…
Browse files Browse the repository at this point in the history
…lts setting is 'dynamic' and the subscriptSizing input is not present. (#24263)
  • Loading branch information
kseamon authored and mmalerba committed Jan 25, 2022
1 parent 2b67397 commit b79406f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const DEFAULT_APPEARANCE: MatFormFieldAppearance = 'fill';
/** Default appearance used by the form-field. */
const DEFAULT_FLOAT_LABEL: FloatLabelType = 'auto';

/** Default way that the suffix element height is set. */
/** Default way that the subscript element height is set. */
const DEFAULT_SUBSCRIPT_SIZING: SubscriptSizing = 'fixed';

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ export class MatFormField
set subscriptSizing(value: SubscriptSizing) {
this._subscriptSizing = value || this._defaults?.subscriptSizing || DEFAULT_SUBSCRIPT_SIZING;
}
private _subscriptSizing: SubscriptSizing = DEFAULT_SUBSCRIPT_SIZING;
private _subscriptSizing: SubscriptSizing | null = null;

/** Text for the form field hint. */
@Input()
Expand Down
21 changes: 20 additions & 1 deletion src/material-experimental/mdc-input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ describe('MatFormField default options', () => {
);
});

it('changes the default value of subscriptSizing', () => {
it('changes the default value of subscriptSizing (undefined input)', () => {
const fixture = createComponent(MatInputWithSubscriptSizing, [
{
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
Expand All @@ -1448,6 +1448,25 @@ describe('MatFormField default options', () => {
.classList.contains('mat-mdc-form-field-subscript-dynamic-size'),
).toBe(true);
});

it('changes the default value of subscriptSizing (no input)', () => {
const fixture = createComponent(MatInputWithAppearance, [
{
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
useValue: {
subscriptSizing: 'dynamic',
},
},
]);

fixture.detectChanges();
expect(fixture.componentInstance.formField.subscriptSizing).toBe('dynamic');
expect(
fixture.nativeElement
.querySelector('.mat-mdc-form-field-subscript-wrapper')
.classList.contains('mat-mdc-form-field-subscript-dynamic-size'),
).toBe(true);
});
});

function configureTestingModule(
Expand Down

0 comments on commit b79406f

Please sign in to comment.