@@ -43,7 +43,9 @@ describe('MdSelect', () => {
4343 ThrowsErrorOnInit ,
4444 BasicSelectOnPush ,
4545 BasicSelectOnPushPreselected ,
46- SelectWithPlainTabindex
46+ SelectWithPlainTabindex ,
47+ BasicSelectInitiallyHidden ,
48+ BasicSelectNoPlaceholder
4749 ] ,
4850 providers : [
4951 { provide : OverlayContainer , useFactory : ( ) => {
@@ -155,6 +157,25 @@ describe('MdSelect', () => {
155157 } ) ;
156158 } ) ) ;
157159
160+ it ( 'should set the width of the overlay if the element was hidden initially' , async ( ( ) => {
161+ let initiallyHidden = TestBed . createComponent ( BasicSelectInitiallyHidden ) ;
162+
163+ initiallyHidden . detectChanges ( ) ;
164+ trigger = initiallyHidden . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
165+ trigger . style . width = '200px' ;
166+
167+ initiallyHidden . componentInstance . isVisible = true ;
168+ initiallyHidden . detectChanges ( ) ;
169+
170+ initiallyHidden . whenStable ( ) . then ( ( ) => {
171+ trigger . click ( ) ;
172+ initiallyHidden . detectChanges ( ) ;
173+
174+ const pane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
175+ expect ( pane . style . minWidth ) . toBe ( '200px' ) ;
176+ } ) ;
177+ } ) ) ;
178+
158179 it ( 'should not attempt to open a select that does not have any options' , ( ) => {
159180 fixture . componentInstance . foods = [ ] ;
160181 fixture . detectChanges ( ) ;
@@ -165,6 +186,21 @@ describe('MdSelect', () => {
165186 expect ( fixture . componentInstance . select . panelOpen ) . toBe ( false ) ;
166187 } ) ;
167188
189+ it ( 'should set the width of the overlay if there is no placeholder' , async ( ( ) => {
190+ let noPlaceholder = TestBed . createComponent ( BasicSelectNoPlaceholder ) ;
191+
192+ noPlaceholder . detectChanges ( ) ;
193+ trigger = noPlaceholder . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
194+
195+ noPlaceholder . whenStable ( ) . then ( ( ) => {
196+ trigger . click ( ) ;
197+ noPlaceholder . detectChanges ( ) ;
198+
199+ const pane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
200+ expect ( parseInt ( pane . style . minWidth ) ) . toBeGreaterThan ( 0 ) ;
201+ } ) ;
202+ } ) ) ;
203+
168204 } ) ;
169205
170206 describe ( 'selection logic' , ( ) => {
@@ -1893,6 +1929,27 @@ class MultiSelect {
18931929} )
18941930class SelectWithPlainTabindex { }
18951931
1932+ @Component ( {
1933+ selector : 'basic-select-initially-hidden' ,
1934+ template : `
1935+ <md-select [style.display]="isVisible ? 'block' : 'none'">
1936+ <md-option value="value">There are no other options</md-option>
1937+ </md-select>
1938+ `
1939+ } )
1940+ class BasicSelectInitiallyHidden {
1941+ isVisible = false ;
1942+ }
1943+
1944+ @Component ( {
1945+ selector : 'basic-select-no-placeholder' ,
1946+ template : `
1947+ <md-select>
1948+ <md-option value="value">There are no other options</md-option>
1949+ </md-select>
1950+ `
1951+ } )
1952+ class BasicSelectNoPlaceholder { }
18961953
18971954class FakeViewportRuler {
18981955 getViewportRect ( ) {
0 commit comments