Skip to content
Merged
Changes from all commits
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
13 changes: 13 additions & 0 deletions src/utils/keyboardNav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Keyboard navigation helpers
export const KEYS = { ENTER: 'Enter', ESCAPE: 'Escape', ARROW_UP: 'ArrowUp', ARROW_DOWN: 'ArrowDown', TAB: 'Tab', SPACE: ' ' } as const;

export function isNavigationKey(key: string): boolean {
return Object.values(KEYS).includes(key as typeof KEYS[keyof typeof KEYS]);
}

export function handleListNavigation(e: KeyboardEvent, items: HTMLElement[], currentIndex: number): number {
if (e.key === KEYS.ARROW_DOWN) return Math.min(currentIndex + 1, items.length - 1);
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: ArrowDown navigation can return -1 when the list is empty, producing an invalid index.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/keyboardNav.ts, line 9:

<comment>ArrowDown navigation can return `-1` when the list is empty, producing an invalid index.</comment>

<file context>
@@ -0,0 +1,13 @@
+}
+
+export function handleListNavigation(e: KeyboardEvent, items: HTMLElement[], currentIndex: number): number {
+  if (e.key === KEYS.ARROW_DOWN) return Math.min(currentIndex + 1, items.length - 1);
+  if (e.key === KEYS.ARROW_UP) return Math.max(currentIndex - 1, 0);
+  return currentIndex;
</file context>
Fix with Cubic

if (e.key === KEYS.ARROW_UP) return Math.max(currentIndex - 1, 0);
return currentIndex;
}

Loading