@@ -10,6 +10,7 @@ import {
1010 ControlValueAccessor , FormControl , FormsModule , NG_VALUE_ACCESSOR , ReactiveFormsModule
1111} from '@angular/forms' ;
1212import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
13+ import { MdInput } from '../input/input' ;
1314
1415describe ( 'MdSelect' , ( ) => {
1516 let overlayContainerElement : HTMLElement ;
@@ -20,6 +21,7 @@ describe('MdSelect', () => {
2021 imports : [ MdSelectModule . forRoot ( ) , ReactiveFormsModule , FormsModule ] ,
2122 declarations : [
2223 BasicSelect ,
24+ SearchSelect ,
2325 NgModelSelect ,
2426 ManySelects ,
2527 NgIfSelect ,
@@ -1255,6 +1257,56 @@ describe('MdSelect', () => {
12551257 expect ( fixture . componentInstance . changeListener ) . toHaveBeenCalledTimes ( 1 ) ;
12561258 } ) ;
12571259 } ) ;
1260+
1261+ describe ( 'Search input' , ( ) => {
1262+ let fixture : ComponentFixture < SearchSelect > ;
1263+
1264+ beforeEach ( ( ) => {
1265+ fixture = TestBed . createComponent ( SearchSelect ) ;
1266+ fixture . detectChanges ( ) ;
1267+
1268+ let trigger = fixture . debugElement . query ( By . css ( '.md-select-trigger' ) ) . nativeElement ;
1269+ trigger . click ( ) ;
1270+ fixture . detectChanges ( ) ;
1271+ } ) ;
1272+
1273+ it ( 'should hide elements that are not in the filter' , ( ) => {
1274+ fixture . componentInstance . select . _onSearch ( 'steak' ) ;
1275+ fixture . detectChanges ( ) ;
1276+
1277+ fixture . whenStable ( ) . then ( ( ) =>
1278+ {
1279+ let options = overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
1280+
1281+ expect ( options [ 0 ] . getAttribute ( 'hidden' ) ) . toEqual ( null ) ;
1282+ expect ( options [ 1 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1283+ expect ( options [ 2 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1284+ expect ( options [ 3 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1285+ expect ( options [ 4 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1286+ expect ( options [ 5 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1287+ expect ( options [ 6 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1288+ expect ( options [ 7 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1289+ } ) ;
1290+ } ) ;
1291+
1292+ it ( 'should should not be case sensitive' , ( ) => {
1293+ fixture . componentInstance . select . _onSearch ( 'S-' ) ;
1294+ fixture . detectChanges ( ) ;
1295+
1296+ fixture . whenStable ( ) . then ( ( ) => {
1297+ let options = overlayContainerElement . querySelectorAll ( 'md-option' ) as NodeListOf < HTMLElement > ;
1298+
1299+ expect ( options [ 0 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1300+ expect ( options [ 1 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1301+ expect ( options [ 2 ] . getAttribute ( 'hidden' ) ) . toEqual ( null ) ;
1302+ expect ( options [ 3 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1303+ expect ( options [ 4 ] . getAttribute ( 'hidden' ) ) . toEqual ( null ) ;
1304+ expect ( options [ 5 ] . getAttribute ( 'hidden' ) ) . toEqual ( null ) ;
1305+ expect ( options [ 6 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1306+ expect ( options [ 7 ] . getAttribute ( 'hidden' ) ) . toEqual ( 'true' ) ;
1307+ } ) ;
1308+ } ) ;
1309+ } ) ;
12581310} ) ;
12591311
12601312@Component ( {
@@ -1289,6 +1341,38 @@ class BasicSelect {
12891341 @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
12901342}
12911343
1344+ @Component ( {
1345+ selector : 'search-select' ,
1346+ template : `
1347+ <div [style.height.px]="heightAbove"></div>
1348+ <md-select placeholder="Food" [search]="true" [formControl]="control" [required]="isRequired">
1349+ <md-option *ngFor="let food of foods" [value]="food.value" [disabled]="food.disabled">
1350+ {{ food.viewValue }}
1351+ </md-option>
1352+ </md-select>
1353+ <div [style.height.px]="heightBelow"></div>
1354+ `
1355+ } )
1356+ class SearchSelect {
1357+ foods : any [ ] = [
1358+ { value : 'steak-0' , viewValue : 'Steak' } ,
1359+ { value : 'pizza-1' , viewValue : 'Pizza' } ,
1360+ { value : 'tacos-2' , viewValue : 'Tacos' , disabled : true } ,
1361+ { value : 'sandwich-3' , viewValue : 'Sandwich' } ,
1362+ { value : 'chips-4' , viewValue : 'Chips' } ,
1363+ { value : 'eggs-5' , viewValue : 'Eggs' } ,
1364+ { value : 'pasta-6' , viewValue : 'Pasta' } ,
1365+ { value : 'sushi-7' , viewValue : 'Sushi' } ,
1366+ ] ;
1367+ control = new FormControl ( ) ;
1368+ isRequired : boolean ;
1369+ heightAbove = 0 ;
1370+ heightBelow = 0 ;
1371+
1372+ @ViewChild ( MdSelect ) select : MdSelect ;
1373+ @ViewChildren ( MdOption ) options : QueryList < MdOption > ;
1374+ }
1375+
12921376@Component ( {
12931377 selector : 'ng-model-select' ,
12941378 template : `
0 commit comments