@@ -48,7 +48,8 @@ describe('MdInputContainer', function () {
4848 MdInputContainerWithStaticPlaceholder ,
4949 MdInputContainerMissingMdInputTestController ,
5050 MdInputContainerMultipleHintTestController ,
51- MdInputContainerMultipleHintMixedTestController
51+ MdInputContainerMultipleHintMixedTestController ,
52+ MdInputContainerWithDynamicPlaceholder
5253 ] ,
5354 } ) ;
5455
@@ -61,8 +62,8 @@ describe('MdInputContainer', function () {
6162
6263 let inputContainer = fixture . debugElement . query ( By . directive ( MdInputContainer ) )
6364 . componentInstance as MdInputContainer ;
64- expect ( inputContainer . floatingPlaceholder ) . toBe ( true ,
65- 'Expected MdInputContainer to default to having floating placeholders turned on ' ) ;
65+ expect ( inputContainer . floatPlaceholder ) . toBe ( 'auto' ,
66+ 'Expected MdInputContainer to set floatingLabel to auto by default. ' ) ;
6667 } ) ;
6768
6869 it ( 'should not be treated as empty if type is date' ,
@@ -477,6 +478,78 @@ describe('MdInputContainer', function () {
477478
478479 expect ( ariaValue ) . toBe ( `${ hintLabel . getAttribute ( 'id' ) } ${ endLabel . getAttribute ( 'id' ) } ` ) ;
479480 } ) ;
481+
482+ it ( 'should float when floatPlaceholder 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' ) ) . nativeElement ;
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 = 'auto' ;
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 . 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 floatPlaceholder is set to true' , ( ) => {
509+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
510+ fixture . detectChanges ( ) ;
511+
512+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
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 . 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 floatPlaceholder is set to false' , ( ) => {
532+ let fixture = TestBed . createComponent ( MdInputContainerWithDynamicPlaceholder ) ;
533+
534+ fixture . componentInstance . shouldFloat = 'never' ;
535+ fixture . detectChanges ( ) ;
536+
537+ let inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
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 . 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+
480553} ) ;
481554
482555@Component ( {
@@ -668,13 +741,23 @@ class MdInputContainerWithValueBinding {
668741
669742@Component ( {
670743 template : `
671- <md-input-container [floatingPlaceholder]="false ">
744+ <md-input-container floatPlaceholder="never ">
672745 <input mdInput placeholder="Label">
673746 </md-input-container>
674747 `
675748} )
676749class MdInputContainerWithStaticPlaceholder { }
677750
751+ @Component ( {
752+ template : `
753+ <md-input-container [floatPlaceholder]="shouldFloat">
754+ <input mdInput placeholder="Label">
755+ </md-input-container>`
756+ } )
757+ class MdInputContainerWithDynamicPlaceholder {
758+ shouldFloat : string = 'always' ;
759+ }
760+
678761@Component ( {
679762 template : `
680763 <md-input-container>
0 commit comments