@@ -47,13 +47,11 @@ class MDCListFoundation extends MDCFoundation {
47
47
return /** @type {!MDCListAdapter } */ ( {
48
48
getListItemCount : ( ) => { } ,
49
49
getFocusedElementIndex : ( ) => { } ,
50
- getListItemIndex : ( ) => { } ,
51
50
setAttributeForElementIndex : ( ) => { } ,
52
51
removeAttributeForElementIndex : ( ) => { } ,
53
52
addClassForElementIndex : ( ) => { } ,
54
53
removeClassForElementIndex : ( ) => { } ,
55
54
focusItemAtIndex : ( ) => { } ,
56
- isListItem : ( ) => { } ,
57
55
setTabIndexForListItemChildren : ( ) => { } ,
58
56
followHref : ( ) => { } ,
59
57
} ) ;
@@ -135,13 +133,9 @@ class MDCListFoundation extends MDCFoundation {
135
133
/**
136
134
* Focus in handler for the list items.
137
135
* @param evt
136
+ * @param {number } listItemIndex
138
137
*/
139
- handleFocusIn ( evt ) {
140
- const listItem = this . getListItem_ ( evt . target ) ;
141
- if ( ! listItem ) return ;
142
-
143
- const listItemIndex = this . adapter_ . getListItemIndex ( listItem ) ;
144
-
138
+ handleFocusIn ( evt , listItemIndex ) {
145
139
if ( listItemIndex >= 0 ) {
146
140
this . adapter_ . setTabIndexForListItemChildren ( listItemIndex , 0 ) ;
147
141
}
@@ -150,12 +144,9 @@ class MDCListFoundation extends MDCFoundation {
150
144
/**
151
145
* Focus out handler for the list items.
152
146
* @param {Event } evt
147
+ * @param {number } listItemIndex
153
148
*/
154
- handleFocusOut ( evt ) {
155
- const listItem = this . getListItem_ ( evt . target ) ;
156
- if ( ! listItem ) return ;
157
- const listItemIndex = this . adapter_ . getListItemIndex ( listItem ) ;
158
-
149
+ handleFocusOut ( evt , listItemIndex ) {
159
150
if ( listItemIndex >= 0 ) {
160
151
this . adapter_ . setTabIndexForListItemChildren ( listItemIndex , - 1 ) ;
161
152
}
@@ -164,8 +155,10 @@ class MDCListFoundation extends MDCFoundation {
164
155
/**
165
156
* Key handler for the list.
166
157
* @param {Event } evt
158
+ * @param {boolean } isRootListItem
159
+ * @param {number } listItemIndex
167
160
*/
168
- handleKeydown ( evt ) {
161
+ handleKeydown ( evt , isRootListItem , listItemIndex ) {
169
162
const arrowLeft = evt . key === 'ArrowLeft' || evt . keyCode === 37 ;
170
163
const arrowUp = evt . key === 'ArrowUp' || evt . keyCode === 38 ;
171
164
const arrowRight = evt . key === 'ArrowRight' || evt . keyCode === 39 ;
@@ -176,10 +169,8 @@ class MDCListFoundation extends MDCFoundation {
176
169
const isSpace = evt . key === 'Space' || evt . keyCode === 32 ;
177
170
178
171
let currentIndex = this . adapter_ . getFocusedElementIndex ( ) ;
179
-
180
172
if ( currentIndex === - 1 ) {
181
- currentIndex = this . adapter_ . getListItemIndex ( this . getListItem_ ( evt . target ) ) ;
182
-
173
+ currentIndex = listItemIndex ;
183
174
if ( currentIndex < 0 ) {
184
175
// If this event doesn't have a mdc-list-item ancestor from the
185
176
// current list (not from a sublist), return early.
@@ -202,11 +193,11 @@ class MDCListFoundation extends MDCFoundation {
202
193
} else if ( this . isSingleSelectionList_ && ( isEnter || isSpace ) ) {
203
194
this . preventDefaultEvent_ ( evt ) ;
204
195
// Check if the space key was pressed on the list item or a child element.
205
- if ( this . adapter_ . isListItem ( evt . target ) ) {
196
+ if ( isRootListItem ) {
206
197
this . setSelectedIndex ( currentIndex ) ;
207
198
208
- // Explicitly activate links, since we're preventing default on Enter, and Space doesn't activate them
209
- this . adapter_ . followHref ( evt . target ) ;
199
+ // Explicitly activate links, since we're preventing default on Enter, and Space doesn't activate them.
200
+ this . adapter_ . followHref ( currentIndex ) ;
210
201
}
211
202
}
212
203
}
@@ -282,20 +273,6 @@ class MDCListFoundation extends MDCFoundation {
282
273
this . adapter_ . focusItemAtIndex ( lastIndex ) ;
283
274
}
284
275
}
285
-
286
- /**
287
- * Utility method to find the first ancestor with the mdc-list-item class.
288
- * @param {EventTarget } target
289
- * @return {?Element }
290
- * @private
291
- */
292
- getListItem_ ( target ) {
293
- while ( ! this . adapter_ . isListItem ( target ) ) {
294
- if ( ! target . parentElement ) return null ;
295
- target = target . parentElement ;
296
- }
297
- return target ;
298
- }
299
276
}
300
277
301
278
export default MDCListFoundation ;
0 commit comments