Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions test/roving-keys.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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\(/)
})
14 changes: 8 additions & 6 deletions web/src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -1582,17 +1583,18 @@ export function Console({machine, onClose, embedded, windowId}: {machine: Machin
<b>{fullscreen ? machine.name : live ? 'Connected' : state === 'connecting' ? 'Connecting…' : state === 'lost' ? 'Reconnecting…' : state === 'superseded' ? 'Opened elsewhere' : 'Unavailable'}</b>
{res && <span className="ct-res">{res.w} × {res.h}</span>}
</span>
<div className="ct-scale" role="radiogroup" aria-label="Display">
<button role="radio" aria-checked={shownScale === 'fit'} className={shownScale === 'fit' ? 'on' : ''} onClick={() => setScale('fit')} title="Scale the picture to fit the window">
<div className="ct-scale" role="radiogroup" aria-label="Display" onKeyDown={(e) => rovingKeyDown(e, RADIO_SELECTOR, 'horizontal')}>
<button role="radio" aria-checked={shownScale === 'fit'} tabIndex={rovingTabIndex(shownScale === 'fit', 0, true)} className={shownScale === 'fit' ? 'on' : ''} onClick={() => setScale('fit')} title="Scale the picture to fit the window">
<Icon name="win-max" size={14} />
Fit
</button>
<button role="radio" aria-checked={shownScale === 'actual'} className={shownScale === 'actual' ? 'on' : ''} onClick={() => setScale('actual')} title="Show every pixel at 100%, with scrollbars">
<button role="radio" aria-checked={shownScale === 'actual'} tabIndex={rovingTabIndex(shownScale === 'actual', 1, true)} className={shownScale === 'actual' ? 'on' : ''} onClick={() => setScale('actual')} title="Show every pixel at 100%, with scrollbars">
100%
</button>
<button
role="radio"
aria-checked={shownScale === 'remote'}
tabIndex={rovingTabIndex(shownScale === 'remote', 2, true)}
className={shownScale === 'remote' ? 'on' : ''}
onClick={() => setScale('remote')}
disabled={live && !canResize}
Expand Down Expand Up @@ -1732,12 +1734,12 @@ export function Console({machine, onClose, embedded, windowId}: {machine: Machin
{live ? 'Connected' : state === 'connecting' ? 'Connecting…' : state === 'lost' ? 'Reconnecting…' : state === 'superseded' ? 'Opened elsewhere' : 'Unavailable'}
</span>
</div>
<div className="mode-switch" role="radiogroup" aria-label="Input mode">
<div className="mode-switch" role="radiogroup" aria-label="Input mode" onKeyDown={(e) => rovingKeyDown(e, RADIO_SELECTOR, 'horizontal')}>
<span className="mode-thumb" style={{transform: `translateX(${mode === 'mouse' ? 100 : 0}%)`}} />
<button role="radio" aria-checked={mode === 'touch'} aria-label="Touch mode: tap where you want to click" onClick={() => setMode('touch')}>
<button role="radio" aria-checked={mode === 'touch'} tabIndex={rovingTabIndex(mode === 'touch', 0, true)} aria-label="Touch mode: tap where you want to click" onClick={() => setMode('touch')}>
<Icon name="finger" size={19} />
</button>
<button role="radio" aria-checked={mode === 'mouse'} aria-label="Mouse mode: use the screen as a trackpad" onClick={() => setMode('mouse')}>
<button role="radio" aria-checked={mode === 'mouse'} tabIndex={rovingTabIndex(mode === 'mouse', 1, true)} aria-label="Mouse mode: use the screen as a trackpad" onClick={() => setMode('mouse')}>
<Icon name="mouse" size={19} />
</button>
</div>
Expand Down
18 changes: 13 additions & 5 deletions web/src/LayoutPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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}
Expand All @@ -59,15 +60,15 @@ function Card({on, suits, art, title, body, onClick, readme}: {on: boolean; suit
)
if (!readme) {
return (
<button type="button" role="radio" aria-checked={on} className={`lp-card${on ? ' on' : ''}`} onClick={onClick}>
<button type="button" role="radio" aria-checked={on} tabIndex={tabIndex} className={`lp-card${on ? ' on' : ''}`} onClick={onClick}>
{picture}
</button>
)
}
// The README control sits on the card, beside the choice, so it is not a second press of the radio.
return (
<div className={`lp-card has-readme${on ? ' on' : ''}`}>
<button type="button" role="radio" aria-checked={on} className="lp-card-hit" onClick={onClick}>
<button type="button" role="radio" aria-checked={on} tabIndex={tabIndex} className="lp-card-hit" onClick={onClick}>
{picture}
</button>
<button
Expand Down Expand Up @@ -102,10 +103,12 @@ export function ScreenLayoutCards({
haptic(6)
onPick(p)
}
const layoutChosen = value === 'desktop' || value === 'phone' || value === 'auto'
return (
<div className={`lp-cards${compact ? ' lp-compact' : ''}`} role="radiogroup" aria-label={label}>
<div className={`lp-cards${compact ? ' lp-compact' : ''}`} role="radiogroup" aria-label={label} onKeyDown={(e) => rovingKeyDown(e, RADIO_SELECTOR)}>
<Card
on={value === 'desktop'}
tabIndex={rovingTabIndex(value === 'desktop', 0, layoutChosen)}
suits={detected}
art={<ArtDesktop />}
title="Desktop"
Expand All @@ -114,6 +117,7 @@ export function ScreenLayoutCards({
/>
<Card
on={value === 'phone'}
tabIndex={rovingTabIndex(value === 'phone', 1, layoutChosen)}
suits={!detected}
art={<ArtPhone />}
title="Phone & tablet"
Expand All @@ -122,6 +126,7 @@ export function ScreenLayoutCards({
/>
<Card
on={value === 'auto'}
tabIndex={rovingTabIndex(value === 'auto', 2, layoutChosen)}
art={<ArtAuto />}
title="Automatic"
body={
Expand Down Expand Up @@ -155,17 +160,20 @@ export function DesktopStyleCards<T extends string>({
haptic(6)
onPick(v)
}
const shapeChosen = value === floating || value === tiling
return (
<div className={`lp-cards lp-cards-2${compact ? ' lp-compact' : ''}`} role="radiogroup" aria-label="Shape">
<div className={`lp-cards lp-cards-2${compact ? ' lp-compact' : ''}`} role="radiogroup" aria-label="Shape" onKeyDown={(e) => rovingKeyDown(e, RADIO_SELECTOR)}>
<Card
on={value === floating}
tabIndex={rovingTabIndex(value === floating, 0, shapeChosen)}
art={<ArtDesktop stayRound />}
title="Round"
body={compact ? 'Rounded. Windows float.' : 'Rounded corners. Floating windows, a dock, and Activities.'}
onClick={() => pick(floating)}
/>
<Card
on={value === tiling}
tabIndex={rovingTabIndex(value === tiling, 1, shapeChosen)}
art={<ArtHyprland />}
title="Square"
body={compact ? 'Square. Windows tile.' : 'Square corners. Tiled windows over a dock, and workspaces 1–9.'}
Expand Down
7 changes: 4 additions & 3 deletions web/src/TerminalTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useEffect, useRef, useState, type ComponentProps} from 'react'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {mutate, query} from './api'
import {Icon} from './icons'
import {rovingKeyDown, rovingTabIndex, TAB_SELECTOR} from './roving'
import {TerminalScreen} from './Terminal'
import {haptic, useConfirm, useToast} from './ui'

Expand Down Expand Up @@ -122,10 +123,10 @@ function TerminalTabSet(props: TabProps) {
}

const bar = (
<div className="term-tabs" role="tablist" aria-label="Terminal tabs" ref={strip}>
{tabs.map((t) => (
<div className="term-tabs" role="tablist" aria-label="Terminal tabs" ref={strip} onKeyDown={(e) => rovingKeyDown(e, TAB_SELECTOR, 'horizontal')}>
{tabs.map((t, index) => (
<div key={t} className={`term-tab${t === current ? ' on' : ''}`}>
<button type="button" role="tab" aria-selected={t === current} className="term-tab-name" onClick={() => (haptic(4), setActive(t))}>
<button type="button" role="tab" aria-selected={t === current} tabIndex={rovingTabIndex(t === current, index, true)} className="term-tab-name" onClick={() => (haptic(4), setActive(t))}>
<Icon name="terminal" size={14} />
{label(t, tabs)}
</button>
Expand Down
7 changes: 4 additions & 3 deletions web/src/backups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -694,9 +695,9 @@ function SetupSheet({mode, current, onClose, onDone}: {mode: 'new' | 'nas'; curr
{shares.length === 0 ? (
<p className="muted">This account can’t see any shared folders on {host}. Create one on the NAS, then try again.</p>
) : (
<div className="glass group" style={{marginBottom: 14}} role="radiogroup" aria-label="Share">
{shares.map((x) => (
<button type="button" key={x.name} className="row" role="radio" aria-checked={share === x.name} onClick={() => (haptic(5), setShare(x.name))} style={{minHeight: 52}}>
<div className="glass group" style={{marginBottom: 14}} role="radiogroup" aria-label="Share" onKeyDown={(e) => rovingKeyDown(e, RADIO_SELECTOR)}>
{shares.map((x, index) => (
<button type="button" key={x.name} className="row" role="radio" aria-checked={share === x.name} tabIndex={rovingTabIndex(share === x.name, index, shares.some((s) => s.name === share))} onClick={() => (haptic(5), setShare(x.name))} style={{minHeight: 52}}>
<span className="row-ico" style={{'--c': 'var(--teal)'} as CSSProperties}>
<Icon name="folder" size={18} />
</span>
Expand Down
6 changes: 4 additions & 2 deletions web/src/character/widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {useAssistantActivity, useAssistantAnimationState, type CharacterState} f
import {assistantIconBadge} from '../assistantLive'
import {useAssistantTurn} from '../assistantTurn'
import {Icon} from '../icons'
import {RADIO_SELECTOR, rovingKeyDown, rovingTabIndex} from '../roving'
import {ToastRow, useAccountToasts} from '../toasts/account'
import {toastSurface} from '../toasts/view'
import {Row, Segmented, Switch, haptic} from '../ui'
Expand Down Expand Up @@ -279,13 +280,14 @@ export function AssistantCharacterWidget({onOpen}: {onOpen: () => void}) {
export function AssistantCharacterPicker({value, focus, onFocus, animate, intensity}: {value: string; focus: string; onFocus: (id: string) => void; animate: boolean; intensity: AssistantLook['intensity']}) {
const [hover, setHover] = useState<string | null>(null)
return (
<div className="ac-picker" role="radiogroup" aria-label="Characters">
{CHARACTERS.map((c) => (
<div className="ac-picker" role="radiogroup" aria-label="Characters" onKeyDown={(e) => rovingKeyDown(e, RADIO_SELECTOR)}>
{CHARACTERS.map((c, index) => (
<button
key={c.id}
type="button"
role="radio"
aria-checked={c.id === focus}
tabIndex={rovingTabIndex(c.id === focus, index, CHARACTERS.some((x) => x.id === focus))}
className={`ac-pick${c.id === value ? ' in-use' : ''}`}
style={{'--ac-1': c.accent} as CSSProperties}
onPointerEnter={() => setHover(c.id)}
Expand Down
9 changes: 5 additions & 4 deletions web/src/desktop/Desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {osLook} from '../osLook'
import {closeAssistantView, keepAssistantWindow, openAssistantView, resetAssistantTurn} from '../assistantTurn'
import {AssistantCharacterWidget} from '../character/widgets'
import {hasOpenDialog, pickFocusTarget, useDialogFocus, useInert, useMenuFocus} from '../focus'
import {rovingKeyDown, rovingTabIndex, TAB_SELECTOR} from '../roving'
import {ScreenErrorBoundary} from '../screenBoundary'
import {queryClearsOnSignOut} from '../signOutQueries'
import {ThemeModeButton} from '../theme/ThemeModeButton'
Expand Down Expand Up @@ -2784,14 +2785,14 @@ function Overview({
</div>
{showApps && railReady && (
<>
<div className="ov-tabs" role="tablist" aria-label="App category">
<button type="button" role="tab" aria-selected={tab === 'all'} className={`ov-tab${tab === 'all' ? ' on' : ''}`} onClick={() => setTab('all')}>
<div className="ov-tabs" role="tablist" aria-label="App category" onKeyDown={(e) => rovingKeyDown(e, TAB_SELECTOR, 'horizontal')}>
<button type="button" role="tab" aria-selected={tab === 'all'} tabIndex={rovingTabIndex(tab === 'all', 0, true)} className={`ov-tab${tab === 'all' ? ' on' : ''}`} onClick={() => setTab('all')}>
All ({webKeys.length + linuxKeys.length})
</button>
<button type="button" role="tab" aria-selected={tab === 'linux'} className={`ov-tab${tab === 'linux' ? ' on' : ''}`} onClick={() => setTab('linux')}>
<button type="button" role="tab" aria-selected={tab === 'linux'} tabIndex={rovingTabIndex(tab === 'linux', 1, true)} className={`ov-tab${tab === 'linux' ? ' on' : ''}`} onClick={() => setTab('linux')}>
Linux Apps (60 FPS GPU · {linuxKeys.length})
</button>
<button type="button" role="tab" aria-selected={tab === 'web'} className={`ov-tab${tab === 'web' ? ' on' : ''}`} onClick={() => setTab('web')}>
<button type="button" role="tab" aria-selected={tab === 'web'} tabIndex={rovingTabIndex(tab === 'web', 2, true)} className={`ov-tab${tab === 'web' ? ' on' : ''}`} onClick={() => setTab('web')}>
Server & Web ({webKeys.length})
</button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion web/src/desktop/hyprland/Bar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Icon} from '../../icons'
import {rovingKeyDown, rovingTabIndex, TAB_SELECTOR} from '../../roving'

export function WorkspacePills({
current,
Expand All @@ -18,7 +19,7 @@ export function WorkspacePills({
<button type="button" className="hypr-menu" aria-label="Launcher" title="Launcher" onClick={onMenu}>
<Icon name="show-apps" size={16} />
</button>
<div className="hypr-pills" role="tablist" aria-label="Workspaces">
<div className="hypr-pills" role="tablist" aria-label="Workspaces" onKeyDown={(e) => rovingKeyDown(e, TAB_SELECTOR, 'horizontal')}>
{Array.from({length: 9}, (_, i) => i + 1).map((n) => {
const on = n === current
const has = occupied.has(n)
Expand All @@ -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)}
>
Expand Down
19 changes: 4 additions & 15 deletions web/src/fleet/MachineTabs.tsx
Original file line number Diff line number Diff line change
@@ -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. */
Expand Down Expand Up @@ -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<HTMLButtonElement>('[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 = (
<div role="tabpanel" aria-labelledby={list ? `mtab-${current.id}` : undefined} tabIndex={-1} className="machine-tab-panel">
<div className="machine-tab-body">{current.body}</div>
Expand All @@ -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 (
<button key={item.id} type="button" role="tab" id={`mtab-${item.id}`} aria-selected={on} tabIndex={on ? 0 : -1} onClick={() => onTab(item.id)}>
<button key={item.id} type="button" role="tab" id={`mtab-${item.id}`} aria-selected={on} tabIndex={rovingTabIndex(on, index, true)} onClick={() => onTab(item.id)}>
{item.label}
</button>
)
Expand Down
7 changes: 4 additions & 3 deletions web/src/fleet/Terminals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -231,9 +232,9 @@ export function Terminals() {
)}
</div>
</div>
<div className="orch-tabs segmented" role="tablist" aria-label="Orchestrator">
{ORCHESTRATOR_TABS.map((item) => (
<button key={item.id} type="button" role="tab" aria-selected={tab === item.id} onClick={() => choose(item.id)}>
<div className="orch-tabs segmented" role="tablist" aria-label="Orchestrator" onKeyDown={(e) => rovingKeyDown(e, TAB_SELECTOR, 'horizontal')}>
{ORCHESTRATOR_TABS.map((item, index) => (
<button key={item.id} type="button" role="tab" aria-selected={tab === item.id} tabIndex={rovingTabIndex(tab === item.id, index, true)} onClick={() => choose(item.id)}>
{item.label}
</button>
))}
Expand Down
Loading
Loading