Skip to content

Commit b79406f

Browse files
kseamonmmalerba
authored andcommittedJan 25, 2022
fix(material-experimental/mdc-form-field): Properly handle when defaults setting is 'dynamic' and the subscriptSizing input is not present. (#24263)
1 parent 2b67397 commit b79406f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed
 

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const DEFAULT_APPEARANCE: MatFormFieldAppearance = 'fill';
9191
/** Default appearance used by the form-field. */
9292
const DEFAULT_FLOAT_LABEL: FloatLabelType = 'auto';
9393

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

9797
/**
@@ -225,7 +225,7 @@ export class MatFormField
225225
set subscriptSizing(value: SubscriptSizing) {
226226
this._subscriptSizing = value || this._defaults?.subscriptSizing || DEFAULT_SUBSCRIPT_SIZING;
227227
}
228-
private _subscriptSizing: SubscriptSizing = DEFAULT_SUBSCRIPT_SIZING;
228+
private _subscriptSizing: SubscriptSizing | null = null;
229229

230230
/** Text for the form field hint. */
231231
@Input()

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ describe('MatFormField default options', () => {
14301430
);
14311431
});
14321432

1433-
it('changes the default value of subscriptSizing', () => {
1433+
it('changes the default value of subscriptSizing (undefined input)', () => {
14341434
const fixture = createComponent(MatInputWithSubscriptSizing, [
14351435
{
14361436
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
@@ -1448,6 +1448,25 @@ describe('MatFormField default options', () => {
14481448
.classList.contains('mat-mdc-form-field-subscript-dynamic-size'),
14491449
).toBe(true);
14501450
});
1451+
1452+
it('changes the default value of subscriptSizing (no input)', () => {
1453+
const fixture = createComponent(MatInputWithAppearance, [
1454+
{
1455+
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
1456+
useValue: {
1457+
subscriptSizing: 'dynamic',
1458+
},
1459+
},
1460+
]);
1461+
1462+
fixture.detectChanges();
1463+
expect(fixture.componentInstance.formField.subscriptSizing).toBe('dynamic');
1464+
expect(
1465+
fixture.nativeElement
1466+
.querySelector('.mat-mdc-form-field-subscript-wrapper')
1467+
.classList.contains('mat-mdc-form-field-subscript-dynamic-size'),
1468+
).toBe(true);
1469+
});
14511470
});
14521471

14531472
function configureTestingModule(

0 commit comments

Comments
 (0)
Please sign in to comment.