Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow / to be entered into search box, don't focus if edit already fo…
…cused
  • Loading branch information
hugovk committed Aug 29, 2023
commit 3f27d34ed682e2fce8dcc56b97bcc9557fb54bbe
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();
}
}
});