add keyboard shortcut to focus search bar #891

This commit is contained in:
FuzzyGrim
2026-02-08 00:00:02 +01:00
parent b008a59663
commit 11745ad3dc
2 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
// Global keyboard shortcut for search
document.addEventListener('keydown', (e) => {
// Ignore if typing in an input, textarea, or contenteditable
const activeEl = document.activeElement;
const isTyping = activeEl.tagName === 'INPUT' ||
activeEl.tagName === 'TEXTAREA' ||
activeEl.isContentEditable;
if (isTyping) return;
if (e.key === '/') {
e.preventDefault();
const searchInput = document.getElementById('global-search');
if (searchInput) {
searchInput.focus();
searchInput.select();
}
}
});

View File

@@ -225,6 +225,7 @@
<div class="relative grow">
{# Search input #}
<input type="search"
id="global-search"
name="q"
value="{{ request.GET.q }}"
:placeholder="getPlaceholder()"
@@ -339,5 +340,6 @@
</script>
<script src="{% static 'js/mediaStatusDateHandler.js' %}{% get_static_file_mtime 'js/mediaStatusDateHandler.js' %}"></script>
<script src="{% static 'js/searchShortcut.js' %}{% get_static_file_mtime 'js/searchShortcut.js' %}"></script>
</body>
</html>