55 ElementRef ,
66 EventEmitter ,
77 Input ,
8- NgZone ,
98 OnDestroy ,
109 Optional ,
1110 Output ,
@@ -71,6 +70,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
7170 /** Whether the select is disabled. */
7271 private _disabled : boolean = false ;
7372
73+ /** The animation state of the placeholder. */
74+ _placeholderState = '' ;
75+
7476 /** Manages keyboard events for options in the panel. */
7577 _keyManager : ListKeyManager ;
7678
@@ -134,8 +136,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
134136 @Output ( ) onClose = new EventEmitter ( ) ;
135137
136138 constructor ( private _element : ElementRef , private _renderer : Renderer ,
137- @Optional ( ) private _dir : Dir , @Optional ( ) public _control : NgControl ,
138- private _ngZone : NgZone ) {
139+ @Optional ( ) private _dir : Dir , @Optional ( ) public _control : NgControl ) {
139140 if ( this . _control ) {
140141 this . _control . valueAccessor = this ;
141142 }
@@ -163,12 +164,16 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
163164 if ( this . disabled ) {
164165 return ;
165166 }
167+ this . _placeholderState = this . _isRtl ( ) ? 'floating-rtl' : 'floating-ltr' ;
166168 this . _panelOpen = true ;
167169 }
168170
169171 /** Closes the overlay panel and focuses the host element. */
170172 close ( ) : void {
171173 this . _panelOpen = false ;
174+ if ( ! this . _selected ) {
175+ this . _placeholderState = '' ;
176+ }
172177 this . _focusHost ( ) ;
173178 }
174179
@@ -182,7 +187,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
182187 // the select's child options have been created. It's necessary to call
183188 // writeValue() again after the options have been created to ensure any
184189 // initial view value is set.
185- this . _ngZone . onStable . first ( ) . subscribe ( ( ) => this . writeValue ( value ) ) ;
190+ Promise . resolve ( null ) . then ( ( ) => this . writeValue ( value ) ) ;
186191 return ;
187192 }
188193
@@ -240,15 +245,6 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
240245 return this . trigger . nativeElement . getBoundingClientRect ( ) . width ;
241246 }
242247
243- /** The animation state of the placeholder. */
244- _getPlaceholderState ( ) : string {
245- if ( this . panelOpen || this . selected ) {
246- return this . _isRtl ( ) ? 'floating-rtl' : 'floating-ltr' ;
247- } else {
248- return 'normal' ;
249- }
250- }
251-
252248 /** The animation state of the overlay panel. */
253249 _getPanelState ( ) : string {
254250 return this . _isRtl ( ) ? `${ this . _transformOrigin } -rtl` : `${ this . _transformOrigin } -ltr` ;
@@ -340,7 +336,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
340336 private _onSelect ( option : MdOption ) : void {
341337 this . _selected = option ;
342338 this . _updateOptions ( ) ;
343- this . close ( ) ;
339+ if ( this . panelOpen ) {
340+ this . close ( ) ;
341+ }
344342 }
345343
346344 /** Deselect each option that doesn't match the current selection. */
0 commit comments