mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-09 01:49:35 -06:00
add global search hotkey
This commit is contained in:
parent
c9f823167c
commit
53b15e3e41
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
28
netbox/project-static/src/hotkeys.ts
Normal file
28
netbox/project-static/src/hotkeys.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const HOTKEYS: Record<string, () => void> = {
|
||||||
|
'/': focusGlobalSearch,
|
||||||
|
};
|
||||||
|
|
||||||
|
function focusGlobalSearch(): void {
|
||||||
|
const searchInput = document.querySelector<HTMLInputElement>('header input[name="q"]')!;
|
||||||
|
searchInput.focus();
|
||||||
|
console.debug('Focused global search input');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent): void {
|
||||||
|
// Ignore hotkeys when focused on form elements or when modal is open
|
||||||
|
if ((event.target as Element).matches('input, textarea, select') || document.body.classList.contains('modal-open')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handler = HOTKEYS[event.key];
|
||||||
|
if (!handler) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initHotkeys(): void {
|
||||||
|
document.addEventListener('keydown', handleKeydown);
|
||||||
|
}
|
||||||
@ -14,6 +14,7 @@ import { initDashboard } from './dashboard';
|
|||||||
import { initRackElevation } from './racks';
|
import { initRackElevation } from './racks';
|
||||||
import { initHtmx } from './htmx';
|
import { initHtmx } from './htmx';
|
||||||
import { initSavedFilterSelect } from './forms/savedFiltersSelect';
|
import { initSavedFilterSelect } from './forms/savedFiltersSelect';
|
||||||
|
import { initHotkeys } from './hotkeys';
|
||||||
|
|
||||||
function initDocument(): void {
|
function initDocument(): void {
|
||||||
for (const init of [
|
for (const init of [
|
||||||
@ -33,6 +34,7 @@ function initDocument(): void {
|
|||||||
initRackElevation,
|
initRackElevation,
|
||||||
initHtmx,
|
initHtmx,
|
||||||
initSavedFilterSelect,
|
initSavedFilterSelect,
|
||||||
|
initHotkeys,
|
||||||
]) {
|
]) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user