Преглед на файлове

Merge pull request #20350 from llamafilm/17824-hotkeys

add global search hotkey
bctiemann преди 8 месеца
родител
ревизия
3c09ee8b11
променени са 4 файла, в които са добавени 31 реда и са изтрити 0 реда
  1. 0 0
      netbox/project-static/dist/netbox.js
  2. 0 0
      netbox/project-static/dist/netbox.js.map
  3. 29 0
      netbox/project-static/src/hotkeys.ts
  4. 2 0
      netbox/project-static/src/netbox.ts

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
netbox/project-static/dist/netbox.js


Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
netbox/project-static/dist/netbox.js.map


+ 29 - 0
netbox/project-static/src/hotkeys.ts

@@ -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);
+}

+ 2 - 0
netbox/project-static/src/netbox.ts

@@ -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();
   }

Някои файлове не бяха показани, защото твърде много файлове са промени