Skip to content

Commit db62e47

Browse files
gemmaronobu
authored andcommitted
Add keydown event listener to focus on search field
1 parent 97325b1 commit db62e47

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div id="search-field-wrapper">
44
<input id="search-field" role="combobox" aria-label="Search"
55
aria-autocomplete="list" aria-controls="search-results"
6-
type="text" name="search" placeholder="Search" spellcheck="false"
6+
type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
77
title="Type to search, Up and Down to navigate, Enter to load">
88
</div>
99

lib/rdoc/generator/template/darkfish/js/darkfish.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,20 @@ function hookSearch() {
7878
search.scrollIntoView = search.scrollInWindow;
7979
};
8080

81+
function hookFocus() {
82+
document.addEventListener("keydown", (event) => {
83+
if (document.activeElement.tagName === 'INPUT') {
84+
return;
85+
}
86+
if (event.key === "/") {
87+
event.preventDefault();
88+
document.querySelector('#search-field').focus();
89+
}
90+
});
91+
}
92+
8193
document.addEventListener('DOMContentLoaded', function() {
8294
hookSourceViews();
8395
hookSearch();
96+
hookFocus();
8497
});

0 commit comments

Comments
 (0)