1
1
import {
2
- AfterContentInit , Directive , ElementRef , Input , ViewContainerRef , Optional , OnDestroy
2
+ AfterContentInit , Directive , ElementRef , Host , Input , ViewContainerRef , Optional , OnDestroy
3
3
} from '@angular/core' ;
4
4
import { NgControl } from '@angular/forms' ;
5
5
import { Overlay , OverlayRef , OverlayState , TemplatePortal } from '../core' ;
@@ -15,6 +15,7 @@ import 'rxjs/add/observable/merge';
15
15
import { Dir } from '../core/rtl/dir' ;
16
16
import 'rxjs/add/operator/startWith' ;
17
17
import 'rxjs/add/operator/switchMap' ;
18
+ import { MdInputContainer , FloatPlaceholderType } from '../input/input-container' ;
18
19
19
20
/**
20
21
* The following style constants are necessary to save here in order
@@ -59,7 +60,8 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
59
60
60
61
constructor ( private _element : ElementRef , private _overlay : Overlay ,
61
62
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 ) { }
63
65
64
66
ngAfterContentInit ( ) {
65
67
this . _keyManager = new ActiveDescendantKeyManager ( this . autocomplete . options ) ;
@@ -90,6 +92,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
90
92
}
91
93
92
94
this . _panelOpen = true ;
95
+ this . _floatPlaceholder ( 'always' ) ;
93
96
}
94
97
95
98
/** Closes the autocomplete suggestion panel. */
@@ -99,6 +102,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
99
102
}
100
103
101
104
this . _panelOpen = false ;
105
+ this . _floatPlaceholder ( 'auto' ) ;
102
106
}
103
107
104
108
/**
@@ -135,6 +139,17 @@ export class MdAutocompleteTrigger implements AfterContentInit, OnDestroy {
135
139
}
136
140
}
137
141
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
+
138
153
/**
139
154
* Given that we are not actually focusing active options, we must manually adjust scroll
140
155
* to reveal options below the fold. First, we find the offset of the option from the top
0 commit comments