Skip to content

Commit 4811b94

Browse files
committed
refactor(tpl): make enableKeyboardNavigate/lookup() more common
1 parent 6b9d41d commit 4811b94

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/tpl/defaultTheme/frontend/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,16 @@
376376
lookupTimer = setTimeout(clearLookupContext, 850);
377377
}
378378

379-
function lookup(key, isBackward) {
379+
function lookup(container, key, isBackward) {
380380
key = key.toLowerCase();
381381

382382
var currentLookupStartA;
383383
if (key === lookupKey) {
384384
// same as last key, lookup next for the same key as prefix
385-
currentLookupStartA = itemList.querySelector(':focus');
385+
currentLookupStartA = container.querySelector(':focus');
386386
} else {
387387
if (!lookupStartA) {
388-
lookupStartA = itemList.querySelector(':focus');
388+
lookupStartA = container.querySelector(':focus');
389389
}
390390
currentLookupStartA = lookupStartA;
391391
if (lookupKey === undefined) {
@@ -397,7 +397,7 @@
397397
lookupBuffer += key;
398398
}
399399
delayClearLookupContext();
400-
return getMatchedFocusableSibling(itemList, isBackward, currentLookupStartA, lookupKey || lookupBuffer);
400+
return getMatchedFocusableSibling(container, isBackward, currentLookupStartA, lookupKey || lookupBuffer);
401401
}
402402

403403
var canArrowMove;
@@ -457,7 +457,7 @@
457457
}
458458
}
459459
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.key.length === 1) {
460-
return lookup(e.key, e.shiftKey);
460+
return lookup(itemList, e.key, e.shiftKey);
461461
}
462462
} else if (e.keyCode) {
463463
if (canArrowMove(e)) {
@@ -489,7 +489,7 @@
489489
}
490490
}
491491
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.keyCode >= 32 && e.keyCode <= 126) {
492-
return lookup(String.fromCharCode(e.keyCode), e.shiftKey);
492+
return lookup(itemList, String.fromCharCode(e.keyCode), e.shiftKey);
493493
}
494494
}
495495
}

0 commit comments

Comments
 (0)