11import {
2- AfterContentInit , Directive , ElementRef , Input , ViewContainerRef , Optional , OnDestroy
2+ AfterContentInit , Directive , ElementRef , Host , Input , ViewContainerRef , Optional , OnDestroy
33} from '@angular/core' ;
44import { NgControl } from '@angular/forms' ;
55import { Overlay , OverlayRef , OverlayState , TemplatePortal } from '../core' ;
@@ -15,6 +15,7 @@ import 'rxjs/add/observable/merge';
1515import { Dir } from '../core/rtl/dir' ;
1616import 'rxjs/add/operator/startWith' ;
1717import 'rxjs/add/operator/switchMap' ;
18+ import { MdInputContainer , FloatPlaceholderType } from '../input/input-container' ;
1819
1920/**
2021 * The following style constants are necessary to save here in order
@@ -59,7 +60,8 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
5960
6061 constructor ( private _element : ElementRef , private _overlay : Overlay ,
6162 private _viewContainerRef : ViewContainerRef ,
62- @Optional ( ) private _controlDir : NgControl , @Optional ( ) private _dir : Dir ) { }
63+ @Optional ( ) private _controlDir : NgControl , @Optional ( ) private _dir : Dir ,
64+ @Optional ( ) @Host ( ) private _inputContainer : MdInputContainer ) { }
6365
6466 ngAfterContentInit ( ) {
6567 this . _keyManager = new ActiveDescendantKeyManager ( this . autocomplete . options ) ;
@@ -90,6 +92,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
9092 }
9193
9294 this . _panelOpen = true ;
95+ this . _floatPlaceholder ( 'always' ) ;
9396 }
9497
9598 /** Closes the autocomplete suggestion panel. */
@@ -99,6 +102,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
99102 }
100103
101104 this . _panelOpen = false ;
105+ this . _floatPlaceholder ( 'auto' ) ;
102106 }
103107
104108 /**
@@ -135,6 +139,17 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
135139 }
136140 }
137141
142+ /**
143+ * In "auto" mode, the placeholder will animate down as soon as focus is lost.
144+ * This causes the value to jump when selecting an option with the mouse.
145+ * This method manually floats the placeholder until the panel can be closed.
146+ */
147+ private _floatPlaceholder ( state : FloatPlaceholderType ) : void {
148+ if ( this . _inputContainer ) {
149+ this . _inputContainer . floatPlaceholder = state ;
150+ }
151+ }
152+
138153 /**
139154 * Given that we are not actually focusing active options, we must manually adjust scroll
140155 * to reveal options below the fold. First, we find the offset of the option from the top
0 commit comments