[ruby/rdoc] Add keydown event listener to focus on search field

https://github.com/ruby/rdoc/commit/db62e47df2
This commit is contained in:
gemmaro 2022-09-24 23:29:51 +09:00 коммит произвёл git
Родитель fd6da40fef
Коммит 77fa4787bd
2 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -3,7 +3,7 @@
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>

Просмотреть файл

@ -78,7 +78,20 @@ function hookSearch() {
search.scrollIntoView = search.scrollInWindow;
};
function hookFocus() {
document.addEventListener("keydown", (event) => {
if (document.activeElement.tagName === 'INPUT') {
return;
}
if (event.key === "/") {
event.preventDefault();
document.querySelector('#search-field').focus();
}
});
}
document.addEventListener('DOMContentLoaded', function() {
hookSourceViews();
hookSearch();
hookFocus();
});