@@ -48,7 +48,8 @@ describe('MdInputContainer', function () {
48
48
MdInputContainerWithStaticPlaceholder ,
49
49
MdInputContainerMissingMdInputTestController ,
50
50
MdInputContainerMultipleHintTestController ,
51
- MdInputContainerMultipleHintMixedTestController
51
+ MdInputContainerMultipleHintMixedTestController ,
52
+ MdInputContainerWithDynamicPlaceholder
52
53
] ,
53
54
} ) ;
54
55
@@ -477,6 +478,78 @@ describe('MdInputContainer', function () {
477
478
478
479
expect ( ariaValue ) . toBe ( `${ hintLabel . getAttribute ( 'id' ) } ${ endLabel . getAttribute ( 'id' ) } ` ) ;
479
480
} ) ;
481
+
482
+ it ( 'should float when floatingPlaceholder is set to default and text is entered' , ( ) => {
483
+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
484
+ fixture . detectChanges ( ) ;
485
+
486
+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
487
+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
488
+
489
+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
490
+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
491
+
492
+ fixture . componentInstance . shouldFloat = null ;
493
+ fixture . detectChanges ( ) ;
494
+
495
+ expect ( labelEl . classList ) . toContain ( 'md-empty' ) ;
496
+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
497
+
498
+ // Update the value of the input.
499
+ inputEl . nativeElement . value = 'Text' ;
500
+
501
+ // Fake behavior of the `(input)` event which should trigger a change detection.
502
+ fixture . detectChanges ( ) ;
503
+
504
+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
505
+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
506
+ } ) ;
507
+
508
+ it ( 'should always float the placeholder when floatingPlaceholder is set to true' , ( ) => {
509
+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
510
+ fixture . detectChanges ( ) ;
511
+
512
+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
513
+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
514
+
515
+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
516
+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
517
+
518
+ fixture . detectChanges ( ) ;
519
+
520
+ // Update the value of the input.
521
+ inputEl . nativeElement . value = 'Text' ;
522
+
523
+ // Fake behavior of the `(input)` event which should trigger a change detection.
524
+ fixture . detectChanges ( ) ;
525
+
526
+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
527
+ expect ( labelEl . classList ) . toContain ( 'md-float' ) ;
528
+ } ) ;
529
+
530
+
531
+ it ( 'should never float the placeholder when floatingPlaceholder is set to false' , ( ) => {
532
+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
533
+
534
+ fixture . componentInstance . shouldFloat = false ;
535
+ fixture . detectChanges ( ) ;
536
+
537
+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
538
+ let labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
539
+
540
+ expect ( labelEl . classList ) . toContain ( 'md-empty' ) ;
541
+ expect ( labelEl . classList ) . not . toContain ( 'md-float' ) ;
542
+
543
+ // Update the value of the input.
544
+ inputEl . nativeElement . value = 'Text' ;
545
+
546
+ // Fake behavior of the `(input)` event which should trigger a change detection.
547
+ fixture . detectChanges ( ) ;
548
+
549
+ expect ( labelEl . classList ) . not . toContain ( 'md-empty' ) ;
550
+ expect ( labelEl . classList ) . not . toContain ( 'md-float' ) ;
551
+ } ) ;
552
+
480
553
} ) ;
481
554
482
555
@Component ( {
@@ -675,6 +748,16 @@ class MdInputContainerWithValueBinding {
675
748
} )
676
749
class MdInputContainerWithStaticPlaceholder { }
677
750
751
+ @Component ( {
752
+ template : `
753
+ <md-input-container [floatingPlaceholder]="shouldFloat">
754
+ <input md-input placeholder="Label">
755
+ </md-input-container>`
756
+ } )
757
+ class MdInputContainerWithDynamicPlaceholder {
758
+ shouldFloat : boolean = true ;
759
+ }
760
+
678
761
@Component ( {
679
762
template : `
680
763
<md-input-container>
0 commit comments