@@ -12,7 +12,7 @@ import {MdOption} from '../core/option/option';
12
12
import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
13
13
import { FakeViewportRuler } from '../core/overlay/position/fake-viewport-ruler' ;
14
14
import { MdAutocomplete } from './autocomplete' ;
15
-
15
+ import { MdInputContainer } from '../input/input-container' ;
16
16
17
17
describe ( 'MdAutocomplete' , ( ) => {
18
18
let overlayContainerElement : HTMLElement ;
@@ -181,16 +181,36 @@ describe('MdAutocomplete', () => {
181
181
. toEqual ( '' , `Expected panel to close when options list is empty.` ) ;
182
182
} ) ;
183
183
} ) ) ;
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
+
184
204
} ) ;
185
205
186
206
it ( 'should have the correct text direction in RTL' , ( ) => {
187
207
dir = 'rtl' ;
188
208
189
- const fixture = TestBed . createComponent ( SimpleAutocomplete ) ;
190
- fixture . detectChanges ( ) ;
209
+ const rtlFixture = TestBed . createComponent ( SimpleAutocomplete ) ;
210
+ rtlFixture . detectChanges ( ) ;
191
211
192
- fixture . componentInstance . trigger . openPanel ( ) ;
193
- fixture . detectChanges ( ) ;
212
+ rtlFixture . componentInstance . trigger . openPanel ( ) ;
213
+ rtlFixture . detectChanges ( ) ;
194
214
195
215
const overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
196
216
expect ( overlayPane . getAttribute ( 'dir' ) ) . toEqual ( 'rtl' ) ;
@@ -603,8 +623,8 @@ describe('MdAutocomplete', () => {
603
623
// Expect option bottom minus the panel height (288 - 256 = 32)
604
624
expect ( scrollContainer . scrollTop ) . toEqual ( 32 , `Expected panel to reveal the sixth option.` ) ;
605
625
} ) ;
606
- } ) ) ;
607
626
627
+ } ) ) ;
608
628
} ) ;
609
629
610
630
describe ( 'aria' , ( ) => {
@@ -793,6 +813,7 @@ class SimpleAutocomplete implements OnDestroy {
793
813
794
814
@ViewChild ( MdAutocompleteTrigger ) trigger : MdAutocompleteTrigger ;
795
815
@ViewChild ( MdAutocomplete ) panel : MdAutocomplete ;
816
+ @ViewChild ( MdInputContainer ) inputContainer : MdInputContainer ;
796
817
@ViewChildren ( MdOption ) options : QueryList < MdOption > ;
797
818
798
819
states = [
0 commit comments