@@ -11,7 +11,7 @@ import {
11
11
} from '@angular/core' ;
12
12
import { MdSelectModule } from './index' ;
13
13
import { OverlayContainer } from '../core/overlay/overlay-container' ;
14
- import { MdSelect } from './select' ;
14
+ import { MdSelect , MdSelectFloatPlaceholderType } from './select' ;
15
15
import { MdOption } from '../core/option/option' ;
16
16
import { Dir } from '../core/rtl/dir' ;
17
17
import {
@@ -35,6 +35,7 @@ describe('MdSelect', () => {
35
35
SelectWithChangeEvent ,
36
36
CustomSelectAccessor ,
37
37
CompWithCustomSelect ,
38
+ FloatPlaceholderSelect ,
38
39
SelectWithErrorSibling ,
39
40
ThrowsErrorOnInit ,
40
41
BasicSelectOnPush
@@ -590,20 +591,20 @@ describe('MdSelect', () => {
590
591
} ) ;
591
592
592
593
it ( 'should float the placeholder when the panel is open and unselected' , ( ) => {
593
- expect ( fixture . componentInstance . select . _placeholderState )
594
+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
594
595
. toEqual ( '' , 'Expected placeholder to initially have a normal position.' ) ;
595
596
596
597
trigger . click ( ) ;
597
598
fixture . detectChanges ( ) ;
598
- expect ( fixture . componentInstance . select . _placeholderState )
599
+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
599
600
. toEqual ( 'floating-ltr' , 'Expected placeholder to animate up to floating position.' ) ;
600
601
601
602
const backdrop =
602
603
overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
603
604
backdrop . click ( ) ;
604
605
fixture . detectChanges ( ) ;
605
606
606
- expect ( fixture . componentInstance . select . _placeholderState )
607
+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
607
608
. toEqual ( '' , 'Expected placeholder to animate back down to normal position.' ) ;
608
609
} ) ;
609
610
@@ -616,7 +617,7 @@ describe('MdSelect', () => {
616
617
617
618
expect ( placeholderEl . classList )
618
619
. toContain ( 'mat-floating-placeholder' , 'Expected placeholder to display as floating.' ) ;
619
- expect ( fixture . componentInstance . select . _placeholderState )
620
+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
620
621
. toEqual ( '' , 'Expected animation state to be empty to avoid animation.' ) ;
621
622
} ) ;
622
623
@@ -625,7 +626,8 @@ describe('MdSelect', () => {
625
626
626
627
trigger . click ( ) ;
627
628
fixture . detectChanges ( ) ;
628
- expect ( fixture . componentInstance . select . _placeholderState ) . toEqual ( 'floating-rtl' ) ;
629
+ expect ( fixture . componentInstance . select . _getPlaceholderAnimationState ( ) )
630
+ . toEqual ( 'floating-rtl' ) ;
629
631
} ) ;
630
632
631
633
@@ -1285,6 +1287,39 @@ describe('MdSelect', () => {
1285
1287
} ) ;
1286
1288
} ) ;
1287
1289
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
+
1288
1323
describe ( 'with OnPush change detection' , ( ) => {
1289
1324
let fixture : ComponentFixture < BasicSelectOnPush > ;
1290
1325
let trigger : HTMLElement ;
@@ -1309,6 +1344,7 @@ describe('MdSelect', () => {
1309
1344
} ) ;
1310
1345
} ) ;
1311
1346
1347
+
1312
1348
@Component ( {
1313
1349
selector : 'basic-select' ,
1314
1350
template : `
@@ -1529,6 +1565,29 @@ class BasicSelectOnPush {
1529
1565
@ViewChildren ( MdOption ) options : QueryList < MdOption > ;
1530
1566
}
1531
1567
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
+
1532
1591
1533
1592
/**
1534
1593
* TODO: Move this to core testing utility until Angular has event faking
0 commit comments