From 0d8597a3e9c0ca74fa346170e8da9e2fc30d64ae Mon Sep 17 00:00:00 2001 From: Joseph Woolley Date: Sat, 5 Dec 2026 09:04:52 -0500 Subject: [PATCH] Move focus with the arrow keys in the remaining tab and radio groups. Arrow keys, Home, and End move through display scale, input mode, layouts, terminal tabs, backup shares, characters, app categories, workspaces, orchestrator tabs, machine sections, hardware choices, wallpapers, and the other computer's operating system. Tab still stops on the selected item only. Enter or Space still chooses. Fixes #513. Co-Authored-By: Grok 4.7 --- test/roving-keys.test.mjs | 22 ++++++++++++++++++++++ web/src/Console.tsx | 14 ++++++++------ web/src/LayoutPicker.tsx | 18 +++++++++++++----- web/src/TerminalTabs.tsx | 7 ++++--- web/src/backups.tsx | 7 ++++--- web/src/character/widgets.tsx | 6 ++++-- web/src/desktop/Desktop.tsx | 9 +++++---- web/src/desktop/hyprland/Bar.tsx | 4 +++- web/src/fleet/MachineTabs.tsx | 19 ++++--------------- web/src/fleet/Terminals.tsx | 7 ++++--- web/src/machines/HardwarePanel.tsx | 7 ++++--- web/src/screens/Assistant.tsx | 7 ++++--- web/src/swarm/Swarm.tsx | 7 ++++--- 13 files changed, 83 insertions(+), 51 deletions(-) diff --git a/test/roving-keys.test.mjs b/test/roving-keys.test.mjs index 3aa5c5df..1f8f662c 100644 --- a/test/roving-keys.test.mjs +++ b/test/roving-keys.test.mjs @@ -65,3 +65,25 @@ test('the app sheet and store tabs and the theme and accent radios use the same assert.match(read('src/ui.tsx'), /rovingKeyDown\(e, RADIO_SELECTOR\)/) assert.match(read('src/OmarchyThemes.tsx'), /rovingKeyDown\(e, RADIO_SELECTOR\)/) }) + +test('the remaining tab lists and radio groups use the same helper', () => { + const consoleSrc = read('src/Console.tsx') + assert.equal(consoleSrc.match(/rovingKeyDown\(e, RADIO_SELECTOR, 'horizontal'\)/g)?.length, 2) + assert.match(consoleSrc, /rovingTabIndex\(/) + const layout = read('src/LayoutPicker.tsx') + assert.equal(layout.match(/rovingKeyDown\(e, RADIO_SELECTOR\)/g)?.length, 2) + assert.match(layout, /rovingTabIndex\(/) + for (const file of ['src/TerminalTabs.tsx', 'src/desktop/Desktop.tsx', 'src/desktop/hyprland/Bar.tsx', 'src/fleet/Terminals.tsx', 'src/fleet/MachineTabs.tsx']) { + const src = read(file) + assert.match(src, /rovingKeyDown\(e, TAB_SELECTOR, 'horizontal'\)/) + assert.match(src, /rovingTabIndex\(/) + } + for (const file of ['src/backups.tsx', 'src/character/widgets.tsx', 'src/machines/HardwarePanel.tsx', 'src/screens/Assistant.tsx']) { + const src = read(file) + assert.match(src, /rovingKeyDown\(e, RADIO_SELECTOR\)/) + assert.match(src, /rovingTabIndex\(/) + } + const swarm = read('src/swarm/Swarm.tsx') + assert.match(swarm, /rovingKeyDown\(e, RADIO_SELECTOR, 'horizontal'\)/) + assert.match(swarm, /rovingTabIndex\(/) +}) diff --git a/web/src/Console.tsx b/web/src/Console.tsx index c06400c2..83eeb587 100644 --- a/web/src/Console.tsx +++ b/web/src/Console.tsx @@ -21,6 +21,7 @@ import {consoleShouldTakeFocus} from './consoleFocus' import {BTN, bindConsoleWheel, charKeySteps, consoleDisconnectAction, consoleFailureMessage, effectiveConsoleScale, handleConsoleWheel, keepSizeZoom, keysymOfChar, mouseButtonFromEvent, nextTwoFingerGesture, PASTE_STEP_MS, pasteKeySequence, pasteKeySteps, pointToFb, readConsoleMetrics, reconcilePointerIds, resolveSuperKey, screenshotFilename, shouldSendConsoleInput, stalePointersOnPrimary, touchReleaseAction, type Pt, type SuperKey} from './consoleHelpers' import {overlayBackUsesHistory, popstateClosesOverlay} from './overlayHistory' import {Icon} from './icons' +import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from './roving' import {keysymFromEvent, setConsoleKeyHandler} from './desktop/hyprland/consoleBridge' import {useMenuFocus} from './focus' import {haptic, settleViewport, usePortalRoot, useScreenLock, useToast} from './ui' @@ -1582,17 +1583,18 @@ export function Console({machine, onClose, embedded, windowId}: {machine: Machin {fullscreen ? machine.name : live ? 'Connected' : state === 'connecting' ? 'Connecting…' : state === 'lost' ? 'Reconnecting…' : state === 'superseded' ? 'Opened elsewhere' : 'Unavailable'} {res && {res.w} × {res.h}} -
- -
-
+
rovingKeyDown(e, RADIO_SELECTOR, 'horizontal')}> - -
diff --git a/web/src/LayoutPicker.tsx b/web/src/LayoutPicker.tsx index 320e3333..05491092 100644 --- a/web/src/LayoutPicker.tsx +++ b/web/src/LayoutPicker.tsx @@ -3,6 +3,7 @@ // so they're shown bigger than themes. import type {ReactNode} from 'react' +import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from './roving' import type {LayoutPref} from './ui' import {haptic} from './ui' @@ -44,7 +45,7 @@ function ArtHyprland() { ) } -function Card({on, suits, art, title, body, onClick, readme}: {on: boolean; suits?: boolean; art: ReactNode; title: string; body: string; onClick: () => void; readme?: () => void}) { +function Card({on, suits, art, title, body, onClick, readme, tabIndex}: {on: boolean; suits?: boolean; art: ReactNode; title: string; body: string; onClick: () => void; readme?: () => void; tabIndex: 0 | -1}) { const picture = ( <> {art} @@ -59,7 +60,7 @@ function Card({on, suits, art, title, body, onClick, readme}: {on: boolean; suit ) if (!readme) { return ( - ) @@ -67,7 +68,7 @@ function Card({on, suits, art, title, body, onClick, readme}: {on: boolean; suit // The README control sits on the card, beside the choice, so it is not a second press of the radio. return (
- diff --git a/web/src/backups.tsx b/web/src/backups.tsx index e0b49daa..8088fc06 100644 --- a/web/src/backups.tsx +++ b/web/src/backups.tsx @@ -10,6 +10,7 @@ import {queryProblem, useBrowserOnline} from './connection' import {errorText} from './queryNotice' import {Icon} from './icons' import {QuickTransferSheet} from './screens/QuickTransfer' +import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from './roving' import {Field, Group, Row, Segmented, Sheet, SheetHeader, Switch, bytes, haptic, useConfirm, useToast} from './ui' type Nas = {host: string; port?: number; share: string; folder: string; username: string; domain?: string; hasPassword?: boolean} @@ -694,9 +695,9 @@ function SetupSheet({mode, current, onClose, onDone}: {mode: 'new' | 'nas'; curr {shares.length === 0 ? (

This account can’t see any shared folders on {host}. Create one on the NAS, then try again.

) : ( -
- {shares.map((x) => ( -
{showApps && railReady && ( <> -
- - -
diff --git a/web/src/desktop/hyprland/Bar.tsx b/web/src/desktop/hyprland/Bar.tsx index 101034c8..f9ed32ea 100644 --- a/web/src/desktop/hyprland/Bar.tsx +++ b/web/src/desktop/hyprland/Bar.tsx @@ -1,4 +1,5 @@ import {Icon} from '../../icons' +import {rovingKeyDown, rovingTabIndex, TAB_SELECTOR} from '../../roving' export function WorkspacePills({ current, @@ -18,7 +19,7 @@ export function WorkspacePills({ -
+
rovingKeyDown(e, TAB_SELECTOR, 'horizontal')}> {Array.from({length: 9}, (_, i) => i + 1).map((n) => { const on = n === current const has = occupied.has(n) @@ -29,6 +30,7 @@ export function WorkspacePills({ role="tab" aria-selected={on} aria-label={`Workspace ${n}`} + tabIndex={rovingTabIndex(on, n - 1, current >= 1 && current <= 9)} className={`hypr-pill${on ? ' on' : ''}${has ? ' occ' : ''}${min && !has ? ' min' : ''}`} onClick={() => onSwitch(n)} > diff --git a/web/src/fleet/MachineTabs.tsx b/web/src/fleet/MachineTabs.tsx index 23ff0de7..18d49a0f 100644 --- a/web/src/fleet/MachineTabs.tsx +++ b/web/src/fleet/MachineTabs.tsx @@ -1,5 +1,6 @@ import {useEffect, useRef, type ReactNode} from 'react' +import {rovingKeyDown, rovingTabIndex, TAB_SELECTOR} from '../roving' import {Sheet} from '../ui' /** Phone uses a sheet. The desktop Machines window embeds the same page beside the list. */ @@ -28,14 +29,6 @@ export function MachineTabs({label, tabs, tab, onTab, list = true}: {label: stri el?.scrollIntoView({block: 'nearest', inline: 'nearest', container: 'nearest'} as ScrollIntoViewOptions) }, [selected]) if (!current) return null - const move = (key: string) => { - const buttons = [...(listRef.current?.querySelectorAll('[role="tab"]') ?? [])] - const index = buttons.indexOf(document.activeElement as HTMLButtonElement) - if (index < 0) return - const next = key === 'ArrowRight' ? (index + 1) % buttons.length : key === 'ArrowLeft' ? (index - 1 + buttons.length) % buttons.length : key === 'Home' ? 0 : key === 'End' ? buttons.length - 1 : -1 - if (next < 0) return - buttons[next]?.focus() - } const panel = (
{current.body}
@@ -49,16 +42,12 @@ export function MachineTabs({label, tabs, tab, onTab, list = true}: {label: stri className="machine-tabs-list" role="tablist" aria-label={label} - onKeyDown={(e) => { - if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft' && e.key !== 'Home' && e.key !== 'End') return - e.preventDefault() - move(e.key) - }} + onKeyDown={(e) => rovingKeyDown(e, TAB_SELECTOR, 'horizontal')} > - {tabs.map((item) => { + {tabs.map((item, index) => { const on = item.id === selected return ( - ) diff --git a/web/src/fleet/Terminals.tsx b/web/src/fleet/Terminals.tsx index 4f6feb5d..5c5d1439 100644 --- a/web/src/fleet/Terminals.tsx +++ b/web/src/fleet/Terminals.tsx @@ -13,6 +13,7 @@ import {containerAgent, guestAgent, isContainerAgent, isGuestAgent, linuxConnect import {swarmGaugeItems, type SwarmMetrics} from '../swarm/gauges' import {agentMay, useSwarm, type Agent} from '../swarm/Swarm' import {FilterBar} from '../FilterBar' +import {rovingKeyDown, rovingTabIndex, TAB_SELECTOR} from '../roving' import {StatusPill, haptic} from '../ui' import {SERVER_FLEET_ID, containerFleetId} from './list' import {ORCHESTRATOR_TABS, onOrchestratorTab, type OrchFacts, type OrchTab} from './orchestratorLogic' @@ -231,9 +232,9 @@ export function Terminals() { )}
-
- {ORCHESTRATOR_TABS.map((item) => ( - ))} diff --git a/web/src/machines/HardwarePanel.tsx b/web/src/machines/HardwarePanel.tsx index 5c956373..c02cb0ff 100644 --- a/web/src/machines/HardwarePanel.tsx +++ b/web/src/machines/HardwarePanel.tsx @@ -3,6 +3,7 @@ import {useQuery} from '@tanstack/react-query' import {query, type OsImage} from '../api' import {Icon} from '../icons' +import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from '../roving' import {haptic, useConfirm} from '../ui' import {BUS_LABEL, CACHE_LABEL, CPU_LABEL, NIC_LABEL, VIDEO_LABEL, driveName, mib, useMachineAction, useNode, type Drive, type MachineDetails} from './api' import {formatServerDiskGb} from './formatServerDisk' @@ -182,9 +183,9 @@ function ChoiceEdit({value, options, warning, onCancel, onSave, saving}: {value: const [v, setV] = useState(value) return ( <> -
- {options.map((o) => ( - diff --git a/web/src/screens/Assistant.tsx b/web/src/screens/Assistant.tsx index 170d082c..97f93ca2 100644 --- a/web/src/screens/Assistant.tsx +++ b/web/src/screens/Assistant.tsx @@ -32,6 +32,7 @@ import { import {AssistantCharacter, lookName, useAssistantLook} from '../character/AssistantCharacter' import {patchDeskConfig} from '../desktop/config' import {SHOW_SHELL_KEY} from '../desktop/settingsPage' +import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from '../roving' import {haptic, omarchyBackgroundUrl, resetZoom, setLayoutPref, useLayout, useOmarchyThemes, usePortalRoot, useScreenLock, type Prefs} from '../ui' import {handleDocumentLinkClick, renderedHtmlSanitizeConfig} from './viewer/helpers' @@ -139,12 +140,12 @@ function WallpaperPicker({ if (themes.isLoading) return

Looking for wallpapers…

if (!items.length) return

No pictures for this theme.

return ( -
- {items.map((it) => { +
rovingKeyDown(e, RADIO_SELECTOR)}> + {items.map((it, index) => { const on = selected === it.id return ( diff --git a/web/src/swarm/Swarm.tsx b/web/src/swarm/Swarm.tsx index fa722a2c..9aba05f1 100644 --- a/web/src/swarm/Swarm.tsx +++ b/web/src/swarm/Swarm.tsx @@ -51,6 +51,7 @@ import {MachineScreen} from '../desktop/MachineScreen' import {joinedComputerScreen, openMachineTerminal, openRemoteDesktop} from '../desktop/openScreen' import {AgentServices} from './AgentServices' import {ComputerBackups} from '../backups' +import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from '../roving' import {Row, Sheet, SheetHeader, StatChip, StatusPill, Switch, bytes, duration, haptic, useConfirm, useToast} from '../ui' const TerminalTabs = lazy(() => import('../TerminalTabs').then((m) => ({default: m.TerminalTabs}))) @@ -997,9 +998,9 @@ export function AddComputer({before, onClose, onJoined, guest}: {before: string[ ) : ( <> {!guest && ( -
- {(['unix', 'windows'] as const).map((o) => ( - ))}