Skip to content

Commit 22a9637

Browse files
committed
feat(tpl): improve keepFocusOnBackwardForward()
1 parent 4c71255 commit 22a9637

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/tpl/defaultTheme/frontend/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,19 @@
233233

234234
function keepFocusOnBackwardForward() {
235235
if (window.onpageshow === undefined || !document.querySelector) return;
236-
document.body.querySelector('.item-list').addEventListener('focusin', function (e) {
237-
lastFocused = e.target;
238-
});
236+
237+
function onFocus(e) {
238+
var link = e.target;
239+
while (link && !(link instanceof HTMLAnchorElement)) {
240+
link = link.parentElement;
241+
}
242+
if (!link || link === lastFocused) return;
243+
lastFocused = link;
244+
}
245+
246+
var itemList = document.body.querySelector('.item-list');
247+
itemList.addEventListener('focusin', onFocus);
248+
itemList.addEventListener('click', onFocus);
239249
window.addEventListener('pageshow', function () {
240250
if (lastFocused && lastFocused !== document.activeElement) {
241251
lastFocused.focus();

0 commit comments

Comments
 (0)