feat: add keyboard navigation to combobox and select fields on web

This commit is contained in:
Mohamed Boudra
2026-01-30 22:52:07 +07:00
parent 025a68c3a4
commit ea33d1980f
8 changed files with 320 additions and 22 deletions
@@ -0,0 +1,19 @@
export function getNextActiveIndex(args: {
currentIndex: number;
itemCount: number;
key: "ArrowDown" | "ArrowUp";
}): number {
const { currentIndex, itemCount, key } = args;
if (itemCount <= 0) return -1;
if (currentIndex < 0) {
return key === "ArrowDown" ? 0 : itemCount - 1;
}
const normalizedCurrent = currentIndex % itemCount;
return key === "ArrowDown"
? (normalizedCurrent + 1) % itemCount
: (normalizedCurrent - 1 + itemCount) % itemCount;
}