[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 committed by git
parent fd6da40fef
commit 77fa4787bd
2 changed files with 14 additions and 1 deletions

View File

@ -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>

View File

@ -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();
});