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. */
@@ -105,10 +101,6 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
105
101
@Optional ( ) private _dir : Dir , private _zone : NgZone ,
106
102
@Optional ( ) @Host ( ) private _inputContainer : MdInputContainer ) { }
107
103
108
- ngAfterContentInit ( ) {
109
- this . _keyManager = new ActiveDescendantKeyManager ( this . autocomplete . options ) . withWrap ( ) ;
110
- }
111
-
112
104
ngOnDestroy ( ) {
113
105
if ( this . _panelPositionSubscription ) {
114
106
this . _panelPositionSubscription . unsubscribe ( ) ;
@@ -155,7 +147,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
155
147
return Observable . merge (
156
148
this . optionSelections ,
157
149
this . _blurStream . asObservable ( ) ,
158
- this . _keyManager . tabOut
150
+ this . autocomplete . _keyManager . tabOut
159
151
) ;
160
152
}
161
153
@@ -166,7 +158,9 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
166
158
167
159
/** The currently active option, coerced to MdOption type. */
168
160
get activeOption ( ) : MdOption {
169
- return this . _keyManager . activeItem as MdOption ;
161
+ if ( this . autocomplete . _keyManager ) {
162
+ return this . autocomplete . _keyManager . activeItem as MdOption ;
163
+ }
170
164
}
171
165
172
166
/**
@@ -205,7 +199,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
205
199
if ( this . activeOption && event . keyCode === ENTER ) {
206
200
this . activeOption . _selectViaInteraction ( ) ;
207
201
} else {
208
- this . _keyManager . onKeydown ( event ) ;
202
+ this . autocomplete . _keyManager . onKeydown ( event ) ;
209
203
if ( event . keyCode === UP_ARROW || event . keyCode === DOWN_ARROW ) {
210
204
this . openPanel ( ) ;
211
205
this . _scrollToOption ( ) ;
@@ -250,7 +244,8 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
250
244
* height, so the active option will be just visible at the bottom of the panel.
251
245
*/
252
246
private _scrollToOption ( ) : void {
253
- const optionOffset = this . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
247
+ const optionOffset =
248
+ this . autocomplete . _keyManager . activeItemIndex * AUTOCOMPLETE_OPTION_HEIGHT ;
254
249
const newScrollTop =
255
250
Math . max ( 0 , optionOffset - AUTOCOMPLETE_PANEL_HEIGHT + AUTOCOMPLETE_OPTION_HEIGHT ) ;
256
251
this . autocomplete . _setScrollTop ( newScrollTop ) ;
@@ -344,7 +339,7 @@ export class MdAutocompleteTrigger implements AfterContentInit, ControlValueAcce
344
339
345
340
/** Reset active item to null so arrow events will activate the correct options.*/
346
341
private _resetActiveItem ( ) : void {
347
- this . _keyManager . setActiveItem ( null ) ;
342
+ this . autocomplete . _keyManager . setActiveItem ( null ) ;
348
343
}
349
344
350
345
/**
0 commit comments