@@ -11,7 +11,7 @@ import {
1111} from '@angular/core' ;
1212import { MdSelectModule } from './index' ;
1313import { OverlayContainer } from '../core/overlay/overlay-container' ;
14- import { MdSelect } from './select' ;
14+ import { MdSelect , MdSelectFloatPlaceholderType } from './select' ;
1515import { MdOption } from '../core/option/option' ;
1616import { Dir } from '../core/rtl/dir' ;
1717import {
@@ -35,6 +35,7 @@ describe('MdSelect', () => {
3535 SelectWithChangeEvent ,
3636 CustomSelectAccessor ,
3737 CompWithCustomSelect ,
38+ FloatPlaceholderSelect ,
3839 SelectWithErrorSibling ,
3940 ThrowsErrorOnInit ,
4041 BasicSelectOnPush
@@ -590,20 +591,20 @@ describe('MdSelect', () => {
590591 } ) ;
591592
592593 it ( 'should float the placeholder when the panel is open and unselected' , ( ) => {
593- expect ( fixture . componentInstance . select . _placeholderState )
594+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
594595 . toEqual ( '' , 'Expected placeholder to initially have a normal position.' ) ;
595596
596597 trigger . click ( ) ;
597598 fixture . detectChanges ( ) ;
598- expect ( fixture . componentInstance . select . _placeholderState )
599+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
599600 . toEqual ( 'floating-ltr' , 'Expected placeholder to animate up to floating position.' ) ;
600601
601602 const backdrop =
602603 overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
603604 backdrop . click ( ) ;
604605 fixture . detectChanges ( ) ;
605606
606- expect ( fixture . componentInstance . select . _placeholderState )
607+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
607608 . toEqual ( '' , 'Expected placeholder to animate back down to normal position.' ) ;
608609 } ) ;
609610
@@ -616,7 +617,7 @@ describe('MdSelect', () => {
616617
617618 expect ( placeholderEl . classList )
618619 . toContain ( 'mat-floating-placeholder' , 'Expected placeholder to display as floating.' ) ;
619- expect ( fixture . componentInstance . select . _placeholderState )
620+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
620621 . toEqual ( '' , 'Expected animation state to be empty to avoid animation.' ) ;
621622 } ) ;
622623
@@ -625,7 +626,8 @@ describe('MdSelect', () => {
625626
626627 trigger . click ( ) ;
627628 fixture . detectChanges ( ) ;
628- expect ( fixture . componentInstance . select . _placeholderState ) . toEqual ( 'floating-rtl' ) ;
629+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
630+ . toEqual ( 'floating-rtl' ) ;
629631 } ) ;
630632
631633
@@ -1285,6 +1287,39 @@ describe('MdSelect', () => {
12851287 } ) ;
12861288 } ) ;
12871289
1290+ describe ( 'floatPlaceholder option' , ( ) => {
1291+ let fixture : ComponentFixture < FloatPlaceholderSelect > ;
1292+
1293+ beforeEach ( ( ) => {
1294+ fixture = TestBed . createComponent ( FloatPlaceholderSelect ) ;
1295+ } ) ;
1296+
1297+ it ( 'should be able to disable the floating placeholder' , ( ) => {
1298+ let placeholder = fixture . debugElement . query ( By . css ( '.mat-select-placeholder' ) ) . nativeElement ;
1299+
1300+ fixture . componentInstance . floatPlaceholder = 'never' ;
1301+ fixture . detectChanges ( ) ;
1302+
1303+ expect ( placeholder . style . visibility ) . toBe ( 'visible' ) ;
1304+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) ) . toBeFalsy ( ) ;
1305+
1306+ fixture . componentInstance . control . setValue ( 'pizza-1' ) ;
1307+ fixture . detectChanges ( ) ;
1308+
1309+ expect ( placeholder . style . visibility ) . toBe ( 'hidden' ) ;
1310+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) ) . toBeFalsy ( ) ;
1311+ } ) ;
1312+
1313+ it ( 'should be able to always float the placeholder' , ( ) => {
1314+ expect ( fixture . componentInstance . control . value ) . toBeFalsy ( ) ;
1315+
1316+ fixture . componentInstance . floatPlaceholder = 'always' ;
1317+ fixture . detectChanges ( ) ;
1318+
1319+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) ) . toBe ( 'floating-ltr' ) ;
1320+ } ) ;
1321+ } ) ;
1322+
12881323 describe ( 'with OnPush change detection' , ( ) => {
12891324 let fixture : ComponentFixture < BasicSelectOnPush > ;
12901325 let trigger : HTMLElement ;
@@ -1309,6 +1344,7 @@ describe('MdSelect', () => {
13091344 } ) ;
13101345} ) ;
13111346
1347+
13121348@Component ( {
13131349 selector : 'basic-select' ,
13141350 template : `
@@ -1529,6 +1565,29 @@ class BasicSelectOnPush {
15291565 @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
15301566}
15311567
1568+ @Component ( {
1569+ selector : 'floating-placeholder-select' ,
1570+ template : `
1571+ <md-select placeholder="Food I want to eat right now" [formControl]="control"
1572+ [floatPlaceholder]="floatPlaceholder">
1573+ <md-option *ngFor="let food of foods" [value]="food.value">
1574+ {{ food.viewValue }}
1575+ </md-option>
1576+ </md-select>
1577+ ` ,
1578+ } )
1579+ class FloatPlaceholderSelect {
1580+ floatPlaceholder : MdSelectFloatPlaceholderType = 'auto' ;
1581+ control = new FormControl ( ) ;
1582+ foods : any [ ] = [
1583+ { value : 'steak-0' , viewValue : 'Steak' } ,
1584+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1585+ { value : 'tacos-2' , viewValue : 'Tacos' }
1586+ ] ;
1587+
1588+ @ViewChild ( MdSelect ) select : MdSelect ;
1589+ }
1590+
15321591
15331592/**
15341593 * TODO: Move this to core testing utility until Angular has event faking
0 commit comments