Skip to content

Commit

Permalink
Allow / to be entered into search box, don't focus if edit already fo…
Browse files Browse the repository at this point in the history
…cused
  • Loading branch information
hugovk committed Aug 29, 2023
1 parent 23f0b42 commit 3f27d34
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions python_docs_theme/static/search-focus.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
function isInputFocused() {
const activeElement = document.activeElement;
return (
activeElement.tagName === 'INPUT' ||
activeElement.tagName === 'TEXTAREA' ||
activeElement.isContentEditable
);
}

document.addEventListener('keydown', function(event) {
if (event.key === '/') {
// Prevent "/" from being entered in the search box
event.preventDefault();
if (!isInputFocused()) {
// Prevent "/" from being entered in the search box
event.preventDefault();

// Set the focus on the search box
let searchBox = document.getElementById('search-box');
searchBox.focus();
// Set the focus on the search box
const searchBox = document.getElementById('search-box');
searchBox.focus();
}
}
});

0 comments on commit 3f27d34

Please sign in to comment.