feat(a11y): add keyboard nav utilities#12
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/utils/keyboardNav.ts">
<violation number="1" location="src/utils/keyboardNav.ts:9">
P2: ArrowDown navigation can return `-1` when the list is empty, producing an invalid index.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| } | ||
|
|
||
| export function handleListNavigation(e: KeyboardEvent, items: HTMLElement[], currentIndex: number): number { | ||
| if (e.key === KEYS.ARROW_DOWN) return Math.min(currentIndex + 1, items.length - 1); |
There was a problem hiding this comment.
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>
Keyboard navigation constants and list navigation handler.
Summary by cubic
Adds keyboard navigation utilities with common key constants and a list navigation helper. Improves accessibility and provides consistent arrow key handling across list-like components.
Written for commit 12d7a0e. Summary will update on new commits.