1
1
import {
2
- AfterContentInit ,
3
2
Directive ,
4
3
ElementRef ,
5
4
forwardRef ,
@@ -17,7 +16,6 @@ import {PositionStrategy} from '../core/overlay/position/position-strategy';
17
16
import { ConnectedPositionStrategy } from '../core/overlay/position/connected-position-strategy' ;
18
17
import { Observable } from 'rxjs/Observable' ;
19
18
import { MdOptionSelectEvent , MdOption } from '../core/option/option' ;
20
- import { ActiveDescendantKeyManager } from '../core/a11y/activedescendant-key-manager' ;
21
19
import { ENTER , UP_ARROW , DOWN_ARROW } from '../core/keyboard/keycodes' ;
22
20
import { Dir } from '../core/rtl/dir' ;
23
21
import { Subscription } from 'rxjs/Subscription' ;
@@ -66,16 +64,14 @@ export const MD_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
66
64
} ,
67
65
providers : [ MD_AUTOCOMPLETE_VALUE_ACCESSOR ]
68
66
} )
69
- export class MdAutocompleteTrigger implements AfterContentInit , ControlValueAccessor , OnDestroy {
67
+ export class MdAutocompleteTrigger implements ControlValueAccessor , OnDestroy {
70
68
private _overlayRef : OverlayRef ;
71
69
private _portal : TemplatePortal ;
72
70
private _panelOpen : boolean = false ;
73
71
74
72
/** The subscription to positioning changes in the autocomplete panel. */
75
73
private _panelPositionSubscription : Subscription ;
76
74
77
- /** Manages active item in option list based on key events. */
78
- private _keyManager : ActiveDescendantKeyManager ;
79
75
private _positionStrategy : ConnectedPositionStrategy ;
80
76
81
77
/** Stream of blur events that should close the panel. */
@@ -108,10 +104,6 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
108
104
@Optional ( ) private _dir : Dir , private _zone : NgZone ,
109
105
@Optional ( ) @Host ( ) private _inputContainer : MdInputContainer ) { }
110
106
111
- ngAfterContentInit ( ) {
112
- this . _keyManager = new ActiveDescendantKeyManager ( this . autocomplete . options ) . withWrap ( ) ;
113
- }
114
-
115
107
ngOnDestroy ( ) {
116
108
if ( this . _panelPositionSubscription ) {
117
109
this . _panelPositionSubscription . unsubscribe ( ) ;
@@ -158,7 +150,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
158
150
return Observable . merge (
159
151
this . optionSelections ,
160
152
this . _blurStream . asObservable ( ) ,
161
- this . _keyManager . tabOut
153
+ this . autocomplete . _keyManager . tabOut
162
154
) ;
163
155
}
164
156
@@ -169,7 +161,9 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
169
161
170
162
/** The currently active option, coerced to MdOption type. */
171
163
get activeOption ( ) : MdOption {
172
- return this . _keyManager . activeItem as MdOption ;
164
+ if ( this . autocomplete . _keyManager ) {
165
+ return this . autocomplete . _keyManager . activeItem as MdOption ;
166
+ }
173
167
}
174
168
175
169
/**
@@ -208,7 +202,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
208
202
if ( this . activeOption && event . keyCode === ENTER ) {
209
203
this . activeOption . _selectViaInteraction ( ) ;
210
204
} else {
211
- this . _keyManager . onKeydown ( event ) ;
205
+ this . autocomplete . _keyManager . onKeydown ( event ) ;
212
206
if ( event . keyCode === UP_ARROW || event . keyCode === DOWN_ARROW ) {
213
207
this . openPanel ( ) ;
214
208
this . _scrollToOption ( ) ;
@@ -262,7 +256,8 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
262
256
* height, so the active option will be just visible at the bottom of the panel.
263
257
*/
264
258
private _scrollToOption ( ) : void {
265
- const optionOffset = this . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
259
+ const optionOffset =
260
+ this . autocomplete . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
266
261
const newScrollTop =
267
262
Math . max ( 0 , optionOffset - AUTOCOMPLETE_PANEL_HEIGHT + AUTOCOMPLETE_OPTION_HEIGHT ) ;
268
263
this . autocomplete . _setScrollTop ( newScrollTop ) ;
@@ -356,7 +351,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
356
351
357
352
/** Reset active item to null so arrow events will activate the correct options.*/
358
353
private _resetActiveItem ( ) : void {
359
- this . _keyManager . setActiveItem ( null ) ;
354
+ this . autocomplete . _keyManager . setActiveItem ( null ) ;
360
355
}
361
356
362
357
/**
0 commit comments