@@ -33,6 +33,7 @@ import {
33
33
import { MatIconModule } from '../icon' ;
34
34
import { By } from '@angular/platform-browser' ;
35
35
import { MAT_INPUT_VALUE_ACCESSOR , MatInput , MatInputModule } from './index' ;
36
+ import { MatFormFieldNotchedOutline } from '../form-field/directives/notched-outline' ;
36
37
37
38
describe ( 'MatMdcInput without forms' , ( ) => {
38
39
it ( 'should default to floating labels' , fakeAsync ( ( ) => {
@@ -607,6 +608,29 @@ describe('MatMdcInput without forms', () => {
607
608
expect ( input . getAttribute ( 'aria-describedby' ) ) . toBe ( `initial ${ hintId } ` ) ;
608
609
} ) ) ;
609
610
611
+ it ( 'should show outline label correctly based on initial condition to false' , fakeAsync ( ( ) => {
612
+ const fixture = createComponent ( MatInputOutlineWithConditionalLabel ) ;
613
+ fixture . detectChanges ( ) ;
614
+ tick ( 16 ) ;
615
+
616
+ const notchedOutline : HTMLElement = fixture . debugElement . query (
617
+ By . directive ( MatFormFieldNotchedOutline ) ,
618
+ ) . nativeElement ;
619
+
620
+ console . log ( 'notchedOutline' , notchedOutline . classList ) ;
621
+
622
+ expect ( notchedOutline . classList ) . toContain ( 'mdc-notched-outline--no-label' ) ;
623
+ expect ( notchedOutline . classList ) . not . toContain ( 'mdc-notched-outline--upgraded' ) ;
624
+
625
+ fixture . componentInstance . showLabel = true ;
626
+ fixture . changeDetectorRef . markForCheck ( ) ;
627
+ fixture . detectChanges ( ) ;
628
+ tick ( 16 ) ;
629
+
630
+ expect ( notchedOutline . classList ) . not . toContain ( 'mdc-notched-outline--no-label' ) ;
631
+ expect ( notchedOutline . classList ) . toContain ( 'mdc-notched-outline--upgraded' ) ;
632
+ } ) ) ;
633
+
610
634
it ( 'supports user binding to aria-describedby' , fakeAsync ( ( ) => {
611
635
let fixture = createComponent ( MatInputWithSubscriptAndAriaDescribedBy ) ;
612
636
@@ -2178,6 +2202,22 @@ class MatInputWithAppearance {
2178
2202
appearance : MatFormFieldAppearance ;
2179
2203
}
2180
2204
2205
+ @Component ( {
2206
+ template : `
2207
+ <mat-form-field appearance="outline">
2208
+ @if(showLabel) {
2209
+ <mat-label>My Label</mat-label>
2210
+ }
2211
+ <input matInput placeholder="Placeholder">
2212
+ </mat-form-field>
2213
+ ` ,
2214
+ standalone : false ,
2215
+ } )
2216
+ class MatInputOutlineWithConditionalLabel {
2217
+ @ViewChild ( MatFormField ) formField : MatFormField ;
2218
+ showLabel : boolean = false ;
2219
+ }
2220
+
2181
2221
@Component ( {
2182
2222
template : `
2183
2223
<mat-form-field [subscriptSizing]="sizing">
0 commit comments