DEV: Use a better selector for search menu (#14390)

".search-menu" matches the parent element of the element that was
previously selected. This is a better choice because it offers some
flexibility over the DOM structure without breaking the keyboard
shortcuts.
This commit is contained in:
Bianca Nenciu 2021-09-21 15:51:29 +03:00 committed by GitHub
parent 27699648ef
commit d940a8e41a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -332,14 +332,14 @@ export default createWidget("search-menu", {
const up = e.which === 38;
const down = e.which === 40;
if (up || down) {
let focused = $("header .panel-body *:focus")[0];
let focused = $(".search-menu *:focus")[0];
if (!focused) {
return;
}
let links = $("header .panel-body .results a");
let results = $("header .panel-body .results .search-link");
let links = $(".search-menu .results a");
let results = $(".search-menu .results .search-link");
let prevResult;
let result;
@ -361,9 +361,9 @@ export default createWidget("search-menu", {
}
if (index === -1 && down) {
$("header .panel-body .search-link:first").focus();
$(".search-menu .search-link:first").focus();
} else if (index === 0 && up) {
$("header .panel-body input:first").focus();
$(".search-menu input:first").focus();
} else if (index > -1) {
index += down ? 1 : -1;
if (index >= 0 && index < results.length) {