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. */
@@ -105,10 +101,6 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
105101 @Optional ( ) private _dir : Dir , private _zone : NgZone ,
106102 @Optional ( ) @Host ( ) private _inputContainer : MdInputContainer ) { }
107103
108- ngAfterContentInit ( ) {
109- this . _keyManager = new ActiveDescendantKeyManager ( this . autocomplete . options ) . withWrap ( ) ;
110- }
111-
112104 ngOnDestroy ( ) {
113105 if ( this . _panelPositionSubscription ) {
114106 this . _panelPositionSubscription . unsubscribe ( ) ;
@@ -155,7 +147,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
155147 return Observable . merge (
156148 this . optionSelections ,
157149 this . _blurStream . asObservable ( ) ,
158- this . _keyManager . tabOut
150+ this . autocomplete . _keyManager . tabOut
159151 ) ;
160152 }
161153
@@ -166,7 +158,9 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
166158
167159 /** The currently active option, coerced to MdOption type. */
168160 get activeOption ( ) : MdOption {
169- return this . _keyManager . activeItem as MdOption ;
161+ if ( this . autocomplete . _keyManager ) {
162+ return this . autocomplete . _keyManager . activeItem as MdOption ;
163+ }
170164 }
171165
172166 /**
@@ -205,7 +199,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
205199 if ( this . activeOption && event . keyCode === ENTER ) {
206200 this . activeOption . _selectViaInteraction ( ) ;
207201 } else {
208- this . _keyManager . onKeydown ( event ) ;
202+ this . autocomplete . _keyManager . onKeydown ( event ) ;
209203 if ( event . keyCode === UP_ARROW || event . keyCode === DOWN_ARROW ) {
210204 this . openPanel ( ) ;
211205 this . _scrollToOption ( ) ;
@@ -250,7 +244,8 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
250244 * height, so the active option will be just visible at the bottom of the panel.
251245 */
252246 private _scrollToOption ( ) : void {
253- const optionOffset = this . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
247+ const optionOffset =
248+ this . autocomplete . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
254249 const newScrollTop =
255250 Math . max ( 0 , optionOffset - AUTOCOMPLETE_PANEL_HEIGHT + AUTOCOMPLETE_OPTION_HEIGHT ) ;
256251 this . autocomplete . _setScrollTop ( newScrollTop ) ;
@@ -344,7 +339,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
344339
345340 /** Reset active item to null so arrow events will activate the correct options.*/
346341 private _resetActiveItem ( ) : void {
347- this . _keyManager . setActiveItem ( null ) ;
342+ this . autocomplete . _keyManager . setActiveItem ( null ) ;
348343 }
349344
350345 /**
0 commit comments