11import {
2- AfterContentInit ,
32 Directive ,
43 ElementRef ,
54 forwardRef ,
@@ -17,7 +16,6 @@ import {PositionStrategy} from '../core/overlay/position/position-strategy';
1716import { ConnectedPositionStrategy } from '../core/overlay/position/connected-position-strategy' ;
1817import { Observable } from 'rxjs/Observable' ;
1918import { MdOptionSelectEvent , MdOption } from '../core/option/option' ;
20- import { ActiveDescendantKeyManager } from '../core/a11y/activedescendant-key-manager' ;
2119import { ENTER , UP_ARROW , DOWN_ARROW } from '../core/keyboard/keycodes' ;
2220import { Dir } from '../core/rtl/dir' ;
2321import { Subscription } from 'rxjs/Subscription' ;
@@ -66,16 +64,14 @@ export const MD_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
6664 } ,
6765 providers : [ MD_AUTOCOMPLETE_VALUE_ACCESSOR ]
6866} )
69- export class MdAutocompleteTrigger implements AfterContentInit , ControlValueAccessor , OnDestroy {
67+ export class MdAutocompleteTrigger implements ControlValueAccessor , OnDestroy {
7068 private _overlayRef : OverlayRef ;
7169 private _portal : TemplatePortal ;
7270 private _panelOpen : boolean = false ;
7371
7472 /** The subscription to positioning changes in the autocomplete panel. */
7573 private _panelPositionSubscription : Subscription ;
7674
77- /** Manages active item in option list based on key events. */
78- private _keyManager : ActiveDescendantKeyManager ;
7975 private _positionStrategy : ConnectedPositionStrategy ;
8076
8177 /** Stream of blur events that should close the panel. */
@@ -108,10 +104,6 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
108104 @Optional ( ) private _dir : Dir , private _zone : NgZone ,
109105 @Optional ( ) @Host ( ) private _inputContainer : MdInputContainer ) { }
110106
111- ngAfterContentInit ( ) {
112- this . _keyManager = new ActiveDescendantKeyManager ( this . autocomplete . options ) . withWrap ( ) ;
113- }
114-
115107 ngOnDestroy ( ) {
116108 if ( this . _panelPositionSubscription ) {
117109 this . _panelPositionSubscription . unsubscribe ( ) ;
@@ -158,7 +150,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
158150 return Observable . merge (
159151 this . optionSelections ,
160152 this . _blurStream . asObservable ( ) ,
161- this . _keyManager . tabOut
153+ this . autocomplete . _keyManager . tabOut
162154 ) ;
163155 }
164156
@@ -169,7 +161,9 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
169161
170162 /** The currently active option, coerced to MdOption type. */
171163 get activeOption ( ) : MdOption {
172- return this . _keyManager . activeItem as MdOption ;
164+ if ( this . autocomplete . _keyManager ) {
165+ return this . autocomplete . _keyManager . activeItem as MdOption ;
166+ }
173167 }
174168
175169 /**
@@ -208,7 +202,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
208202 if ( this . activeOption && event . keyCode === ENTER ) {
209203 this . activeOption . _selectViaInteraction ( ) ;
210204 } else {
211- this . _keyManager . onKeydown ( event ) ;
205+ this . autocomplete . _keyManager . onKeydown ( event ) ;
212206 if ( event . keyCode === UP_ARROW || event . keyCode === DOWN_ARROW ) {
213207 this . openPanel ( ) ;
214208 this . _scrollToOption ( ) ;
@@ -262,7 +256,8 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
262256 * height, so the active option will be just visible at the bottom of the panel.
263257 */
264258 private _scrollToOption ( ) : void {
265- const optionOffset = this . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
259+ const optionOffset =
260+ this . autocomplete . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
266261 const newScrollTop =
267262 Math . max ( 0 , optionOffset - AUTOCOMPLETE_PANEL_HEIGHT + AUTOCOMPLETE_OPTION_HEIGHT ) ;
268263 this . autocomplete . _setScrollTop ( newScrollTop ) ;
@@ -356,7 +351,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
356351
357352 /** Reset active item to null so arrow events will activate the correct options.*/
358353 private _resetActiveItem ( ) : void {
359- this . _keyManager . setActiveItem ( null ) ;
354+ this . autocomplete . _keyManager . setActiveItem ( null ) ;
360355 }
361356
362357 /**
0 commit comments