55 ElementRef ,
66 EventEmitter ,
77 Input ,
8- NgZone ,
98 OnDestroy ,
109 Optional ,
1110 Output ,
@@ -115,6 +114,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
115114 /** The scroll position of the overlay panel, calculated to center the selected option. */
116115 private _scrollTop = 0 ;
117116
117+ /** The animation state of the placeholder. */
118+ _placeholderState = '' ;
119+
118120 /** Manages keyboard events for options in the panel. */
119121 _keyManager : ListKeyManager ;
120122
@@ -193,8 +195,8 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
193195 @Output ( ) onClose = new EventEmitter ( ) ;
194196
195197 constructor ( private _element : ElementRef , private _renderer : Renderer ,
196- private _ngZone : NgZone , private _viewportRuler : ViewportRuler ,
197- @Optional ( ) private _dir : Dir , @ Optional ( ) public _control : NgControl ) {
198+ private _viewportRuler : ViewportRuler , @ Optional ( ) private _dir : Dir ,
199+ @Optional ( ) public _control : NgControl ) {
198200 if ( this . _control ) {
199201 this . _control . valueAccessor = this ;
200202 }
@@ -223,12 +225,16 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
223225 return ;
224226 }
225227 this . _calculateOverlayPosition ( ) ;
228+ this . _placeholderState = this . _isRtl ( ) ? 'floating-rtl' : 'floating-ltr' ;
226229 this . _panelOpen = true ;
227230 }
228231
229232 /** Closes the overlay panel and focuses the host element. */
230233 close ( ) : void {
231234 this . _panelOpen = false ;
235+ if ( ! this . _selected ) {
236+ this . _placeholderState = '' ;
237+ }
232238 this . _focusHost ( ) ;
233239 }
234240
@@ -242,7 +248,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
242248 // the select's child options have been created. It's necessary to call
243249 // writeValue() again after the options have been created to ensure any
244250 // initial view value is set.
245- this . _ngZone . onStable . first ( ) . subscribe ( ( ) => this . writeValue ( value ) ) ;
251+ Promise . resolve ( null ) . then ( ( ) => this . writeValue ( value ) ) ;
246252 return ;
247253 }
248254
@@ -300,15 +306,6 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
300306 return this . _getTriggerRect ( ) . width ;
301307 }
302308
303- /** The animation state of the placeholder. */
304- _getPlaceholderState ( ) : string {
305- if ( this . panelOpen || this . selected ) {
306- return this . _isRtl ( ) ? 'floating-rtl' : 'floating-ltr' ;
307- } else {
308- return 'normal' ;
309- }
310- }
311-
312309 /** Ensures the panel opens if activated by the keyboard. */
313310 _handleKeydown ( event : KeyboardEvent ) : void {
314311 if ( event . keyCode === ENTER || event . keyCode === SPACE ) {
@@ -403,7 +400,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
403400 private _onSelect ( option : MdOption ) : void {
404401 this . _selected = option ;
405402 this . _updateOptions ( ) ;
406- this . close ( ) ;
403+ if ( this . panelOpen ) {
404+ this . close ( ) ;
405+ }
407406 }
408407
409408 /** Deselect each option that doesn't match the current selection. */
0 commit comments