mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-25 12:59:59 -06:00
Merge pull request #20350 from llamafilm/17824-hotkeys
Some checks failed
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
CI / build (20.x, 3.12) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled
Some checks failed
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
CI / build (20.x, 3.12) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled
add global search hotkey
This commit is contained in:
8
netbox/project-static/dist/netbox.js
vendored
8
netbox/project-static/dist/netbox.js
vendored
File diff suppressed because one or more lines are too long
8
netbox/project-static/dist/netbox.js.map
vendored
8
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
29
netbox/project-static/src/hotkeys.ts
Normal file
29
netbox/project-static/src/hotkeys.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
const HOTKEYS: Record<string, () => void> = {
|
||||
'/': focusGlobalSearch,
|
||||
};
|
||||
|
||||
function focusGlobalSearch(): void {
|
||||
const searchInput = document.querySelector<HTMLInputElement>('header input[name="q"]')!;
|
||||
if (searchInput) {
|
||||
searchInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
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 { initHtmx } from './htmx';
|
||||
import { initSavedFilterSelect } from './forms/savedFiltersSelect';
|
||||
import { initHotkeys } from './hotkeys';
|
||||
|
||||
function initDocument(): void {
|
||||
for (const init of [
|
||||
@@ -33,6 +34,7 @@ function initDocument(): void {
|
||||
initRackElevation,
|
||||
initHtmx,
|
||||
initSavedFilterSelect,
|
||||
initHotkeys,
|
||||
]) {
|
||||
init();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user