@@ -32,6 +32,7 @@ import {
32
32
MatFormField ,
33
33
MatFormFieldAppearance ,
34
34
MatFormFieldModule ,
35
+ SubscriptSizing ,
35
36
} from '@angular/material-experimental/mdc-form-field' ;
36
37
import { MatIconModule } from '@angular/material/icon' ;
37
38
import { By } from '@angular/platform-browser' ;
@@ -1406,6 +1407,47 @@ describe('MatFormField default options', () => {
1406
1407
expect ( fixture . componentInstance . formField . hideRequiredMarker ) . toBe ( true ) ;
1407
1408
expect ( fixture . componentInstance . formField . appearance ) . toBe ( 'outline' ) ;
1408
1409
} ) ;
1410
+
1411
+ it ( 'defaults subscriptSizing to false' , ( ) => {
1412
+ const fixture = createComponent ( MatInputWithSubscriptSizing ) ;
1413
+ fixture . detectChanges ( ) ;
1414
+
1415
+ const subscriptElement = fixture . nativeElement . querySelector (
1416
+ '.mat-mdc-form-field-subscript-wrapper' ,
1417
+ ) ;
1418
+
1419
+ expect ( fixture . componentInstance . formField . subscriptSizing ) . toBe ( 'fixed' ) ;
1420
+ expect ( subscriptElement . classList . contains ( 'mat-mdc-form-field-subscript-dynamic-size' ) ) . toBe (
1421
+ false ,
1422
+ ) ;
1423
+
1424
+ fixture . componentInstance . sizing = 'dynamic' ;
1425
+ fixture . detectChanges ( ) ;
1426
+
1427
+ expect ( fixture . componentInstance . formField . subscriptSizing ) . toBe ( 'dynamic' ) ;
1428
+ expect ( subscriptElement . classList . contains ( 'mat-mdc-form-field-subscript-dynamic-size' ) ) . toBe (
1429
+ true ,
1430
+ ) ;
1431
+ } ) ;
1432
+
1433
+ it ( 'changes the default value of subscriptSizing' , ( ) => {
1434
+ const fixture = createComponent ( MatInputWithSubscriptSizing , [
1435
+ {
1436
+ provide : MAT_FORM_FIELD_DEFAULT_OPTIONS ,
1437
+ useValue : {
1438
+ subscriptSizing : 'dynamic' ,
1439
+ } ,
1440
+ } ,
1441
+ ] ) ;
1442
+
1443
+ fixture . detectChanges ( ) ;
1444
+ expect ( fixture . componentInstance . formField . subscriptSizing ) . toBe ( 'dynamic' ) ;
1445
+ expect (
1446
+ fixture . nativeElement
1447
+ . querySelector ( '.mat-mdc-form-field-subscript-wrapper' )
1448
+ . classList . contains ( 'mat-mdc-form-field-subscript-dynamic-size' ) ,
1449
+ ) . toBe ( true ) ;
1450
+ } ) ;
1409
1451
} ) ;
1410
1452
1411
1453
function configureTestingModule (
@@ -1815,6 +1857,19 @@ class MatInputWithAppearance {
1815
1857
appearance : MatFormFieldAppearance ;
1816
1858
}
1817
1859
1860
+ @Component ( {
1861
+ template : `
1862
+ <mat-form-field [subscriptSizing]="sizing">
1863
+ <mat-label>My Label</mat-label>
1864
+ <input matInput placeholder="Placeholder" required>
1865
+ </mat-form-field>
1866
+ ` ,
1867
+ } )
1868
+ class MatInputWithSubscriptSizing {
1869
+ @ViewChild ( MatFormField ) formField : MatFormField ;
1870
+ sizing : SubscriptSizing ;
1871
+ }
1872
+
1818
1873
@Component ( {
1819
1874
template : `
1820
1875
<mat-form-field>
0 commit comments