From 4b81aba42e8ea9a9a84c2af1853bfbcb82bea352 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 27 Sep 2026 20:25:42 -0400 Subject: [PATCH] fix(v2): address Greptile review on spatial navigation Leave the arrows to an expanded popup's activator, so an open RSelect keeps focus, and keep tabindex=-1 anchors and buttons out of the candidates, so a roving grid is entered at its current cell. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../v2/composables/useSpatialNav/index.test.ts | 17 +++++++++++++++++ .../src/v2/composables/useSpatialNav/index.ts | 9 +++++++++ frontend/src/v2/utils/spatialNav.ts | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/frontend/src/v2/composables/useSpatialNav/index.test.ts b/frontend/src/v2/composables/useSpatialNav/index.test.ts index 403afd5c6..a48ea990e 100644 --- a/frontend/src/v2/composables/useSpatialNav/index.test.ts +++ b/frontend/src/v2/composables/useSpatialNav/index.test.ts @@ -132,6 +132,23 @@ describe("useSpatialNav", () => { vi.unstubAllGlobals(); }); + it("skips controls a roving tabindex has taken out of the tab order", () => { + el("tab").setAttribute("tabindex", "-1"); + el("play").focus(); + + expect(press("ArrowDown").defaultPrevented).toBe(false); + expect(document.activeElement).toBe(el("play")); + }); + + it("leaves the arrows to an open popup's activator", () => { + el("tab").setAttribute("aria-haspopup", "listbox"); + el("tab").setAttribute("aria-expanded", "true"); + el("tab").focus(); + + expect(press("ArrowUp").defaultPrevented).toBe(false); + expect(document.activeElement).toBe(el("tab")); + }); + it("stays out of the way while a game is running", () => { storePlaying().setPlaying(true); el("play").focus(); diff --git a/frontend/src/v2/composables/useSpatialNav/index.ts b/frontend/src/v2/composables/useSpatialNav/index.ts index bd9493021..dc068eec0 100644 --- a/frontend/src/v2/composables/useSpatialNav/index.ts +++ b/frontend/src/v2/composables/useSpatialNav/index.ts @@ -34,6 +34,15 @@ const ARROW_OWNING_ROLES = new Set([ function ownsArrowKeys(el: HTMLElement): boolean { if (el.isContentEditable) return true; + // An open popup's activator, such as RSelect's, steers its list by arrow. + const popup = el.getAttribute("aria-haspopup"); + if ( + popup && + popup !== "false" && + el.getAttribute("aria-expanded") === "true" + ) { + return true; + } if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type); if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) { return true; diff --git a/frontend/src/v2/utils/spatialNav.ts b/frontend/src/v2/utils/spatialNav.ts index d45477b61..ed376b683 100644 --- a/frontend/src/v2/utils/spatialNav.ts +++ b/frontend/src/v2/utils/spatialNav.ts @@ -8,8 +8,10 @@ export const FOCUSABLE_SELECTOR = [ "input:not([disabled])", "select:not([disabled])", "textarea:not([disabled])", - "[tabindex]:not([tabindex='-1'])", -].join(","); + "[tabindex]", +] + .map((selector) => `${selector}:not([tabindex='-1'])`) + .join(","); export type SpatialDirection = "up" | "down" | "left" | "right";