@@ -21,7 +21,7 @@ import {
2121 getMatFormFieldDuplicatedHintError ,
2222 getMatFormFieldMissingControlError ,
2323 getMatFormFieldPlaceholderConflictError ,
24- MatFormField ,
24+ MatFormField , MatFormFieldAppearance ,
2525 MatFormFieldModule ,
2626} from '@angular/material/form-field' ;
2727import { By } from '@angular/platform-browser' ;
@@ -1132,6 +1132,76 @@ describe('MatInput with forms', () => {
11321132 } ) ) ;
11331133} ) ;
11341134
1135+ describe ( 'MatInput with appearance' , ( ) => {
1136+ const nonLegacyAppearances : MatFormFieldAppearance [ ] = [ 'standard' , 'box' ] ;
1137+ let fixture : ComponentFixture < MatInputWithAppearance > ;
1138+ let testComponent : MatInputWithAppearance ;
1139+ let containerEl : HTMLElement ;
1140+
1141+ beforeEach ( fakeAsync ( ( ) => {
1142+ TestBed . configureTestingModule ( {
1143+ imports : [
1144+ FormsModule ,
1145+ MatFormFieldModule ,
1146+ MatInputModule ,
1147+ NoopAnimationsModule ,
1148+ PlatformModule ,
1149+ ReactiveFormsModule ,
1150+ ] ,
1151+ declarations : [
1152+ MatInputWithAppearance ,
1153+ ] ,
1154+ } ) ;
1155+
1156+ TestBed . compileComponents ( ) ;
1157+ } ) ) ;
1158+
1159+ beforeEach ( fakeAsync ( ( ) => {
1160+ fixture = TestBed . createComponent ( MatInputWithAppearance ) ;
1161+ fixture . detectChanges ( ) ;
1162+ testComponent = fixture . componentInstance ;
1163+ containerEl = fixture . debugElement . query ( By . css ( 'mat-form-field' ) ) . nativeElement ;
1164+ } ) ) ;
1165+
1166+ it ( 'legacy appearance should promote placeholder to label' , fakeAsync ( ( ) => {
1167+ testComponent . appearance = 'legacy' ;
1168+ fixture . detectChanges ( ) ;
1169+
1170+ expect ( containerEl . classList ) . toContain ( 'mat-form-field-appearance-legacy' ) ;
1171+ expect ( testComponent . formField . _hasFloatingLabel ( ) ) . toBe ( true ) ;
1172+ expect ( testComponent . formField . _hideControlPlaceholder ( ) ) . toBe ( true ) ;
1173+ } ) ) ;
1174+
1175+ it ( 'non-legacy appearances should not promote placeholder to label' , fakeAsync ( ( ) => {
1176+ for ( let appearance of nonLegacyAppearances ) {
1177+ testComponent . appearance = appearance ;
1178+ fixture . detectChanges ( ) ;
1179+
1180+ expect ( containerEl . classList ) . toContain ( `mat-form-field-appearance-${ appearance } ` ) ;
1181+ expect ( testComponent . formField . _hasFloatingLabel ( ) ) . toBe ( false ) ;
1182+ expect ( testComponent . formField . _hideControlPlaceholder ( ) ) . toBe ( false ) ;
1183+ }
1184+ } ) ) ;
1185+
1186+ it ( 'legacy appearance should respect float never' , fakeAsync ( ( ) => {
1187+ testComponent . appearance = 'legacy' ;
1188+ fixture . detectChanges ( ) ;
1189+
1190+ expect ( containerEl . classList ) . toContain ( 'mat-form-field-appearance-legacy' ) ;
1191+ expect ( testComponent . formField . floatLabel ) . toBe ( 'never' ) ;
1192+ } ) ) ;
1193+
1194+ it ( 'non-legacy appearances should not respect float never' , fakeAsync ( ( ) => {
1195+ for ( let appearance of nonLegacyAppearances ) {
1196+ testComponent . appearance = appearance ;
1197+ fixture . detectChanges ( ) ;
1198+
1199+ expect ( containerEl . classList ) . toContain ( `mat-form-field-appearance-${ appearance } ` ) ;
1200+ expect ( testComponent . formField . floatLabel ) . toBe ( 'auto' ) ;
1201+ }
1202+ } ) ) ;
1203+ } ) ;
1204+
11351205@Component ( {
11361206 template : `
11371207 <mat-form-field>
@@ -1467,3 +1537,15 @@ class MatInputWithReadonlyInput {}
14671537class MatInputWithLabelAndPlaceholder {
14681538 floatLabel : FloatLabelType ;
14691539}
1540+
1541+ @Component ( {
1542+ template : `
1543+ <mat-form-field [appearance]="appearance" floatLabel="never">
1544+ <input matInput placeholder="Placeholder">
1545+ </mat-form-field>
1546+ `
1547+ } )
1548+ class MatInputWithAppearance {
1549+ @ViewChild ( MatFormField ) formField : MatFormField ;
1550+ appearance : MatFormFieldAppearance ;
1551+ }
0 commit comments