@@ -12,7 +12,7 @@ import {MdOption} from '../core/option/option';
1212import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
1313import { FakeViewportRuler } from '../core/overlay/position/fake-viewport-ruler' ;
1414import { MdAutocomplete } from './autocomplete' ;
15-
15+ import { MdInputContainer } from '../input/input-container' ;
1616
1717describe ( 'MdAutocomplete' , ( ) => {
1818 let overlayContainerElement : HTMLElement ;
@@ -181,16 +181,36 @@ describe('MdAutocomplete', () => {
181181 . toEqual ( '' , `Expected panel to close when options list is empty.` ) ;
182182 } ) ;
183183 } ) ) ;
184+
185+ it ( 'should keep the label floating until the panel closes' , ( ) => {
186+ fixture . componentInstance . trigger . openPanel ( ) ;
187+ fixture . detectChanges ( ) ;
188+
189+ dispatchEvent ( 'blur' , input ) ;
190+ fixture . detectChanges ( ) ;
191+
192+ expect ( fixture . componentInstance . inputContainer . floatPlaceholder )
193+ . toEqual ( 'always' , 'Expected placeholder to keep floating on blur.' ) ;
194+
195+ const backdrop =
196+ overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
197+ backdrop . click ( ) ;
198+ fixture . detectChanges ( ) ;
199+
200+ expect ( fixture . componentInstance . inputContainer . floatPlaceholder )
201+ . toEqual ( 'auto' , 'Expected placeholder to return to auto state after panel closes.' ) ;
202+ } ) ;
203+
184204 } ) ;
185205
186206 it ( 'should have the correct text direction in RTL' , ( ) => {
187207 dir = 'rtl' ;
188208
189- const fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
190- fixture . detectChanges ( ) ;
209+ const rtlFixture = TestBed . createComponent ( SimpleAutocomplete ) ;
210+ rtlFixture . detectChanges ( ) ;
191211
192- fixture . componentInstance . trigger . openPanel ( ) ;
193- fixture . detectChanges ( ) ;
212+ rtlFixture . componentInstance . trigger . openPanel ( ) ;
213+ rtlFixture . detectChanges ( ) ;
194214
195215 const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
196216 expect ( overlayPane . getAttribute ( 'dir' ) ) . toEqual ( 'rtl' ) ;
@@ -603,8 +623,8 @@ describe('MdAutocomplete', () => {
603623 // Expect option bottom minus the panel height (288 - 256 = 32)
604624 expect ( scrollContainer . scrollTop ) . toEqual ( 32 , `Expected panel to reveal the sixth option.` ) ;
605625 } ) ;
606- } ) ) ;
607626
627+ } ) ) ;
608628 } ) ;
609629
610630 describe ( 'aria' , ( ) => {
@@ -793,6 +813,7 @@ class SimpleAutocomplete implements OnDestroy {
793813
794814 @ViewChild ( MdAutocompleteTrigger ) trigger : MdAutocompleteTrigger ;
795815 @ViewChild ( MdAutocomplete ) panel : MdAutocomplete ;
816+ @ViewChild ( MdInputContainer ) inputContainer : MdInputContainer ;
796817 @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
797818
798819 states = [
0 commit comments