fix(a11y): Run on rows say what Enter does (set location, connect, sign in, plan, overage, payment); Enter on a Connect row connects (DS-22 follow-up)

This commit is contained in:
Neil
2026-11-10 11:22:57 -08:00
parent 29c07ce521
commit 44fef72fd8
7 changed files with 182 additions and 4 deletions
@@ -271,4 +271,66 @@ describe('RunTargetCombobox', () => {
press('Home')
expect(activeText()).toContain('Local Mac')
})
it('tells screen readers what Enter does on rows whose action is not a Tab stop, and Enter does it', () => {
const needsSetup = (name: string, connect: boolean): ProjectHostSetupOption => ({
id: `needs-setup:ssh:${name}`,
kind: 'needs-setup',
projectId: 'p',
hostId: `ssh:${name}`,
label: name,
detail: 'Project location not set',
isAvailable: true,
attention: connect,
canSetLocation: true,
...(connect ? { connectAction: { kind: 'ssh' as const, targetId: name } } : {})
})
const onConnectHost = vi.fn()
const onSetLocation = vi.fn()
act(() => {
root.render(
<TooltipProvider>
<RunTargetCombobox
hostOptions={[...hosts, needsSetup('devbox', false), needsSetup('gpu-box', true)]}
hostValue="mac"
hostExecutionHostId="local"
recipes={[cloud]}
orcaCloudAvailability="offered"
recipeValue={null}
onRecipeChange={vi.fn()}
onAddSshHost={() => {}}
onAddRemoteServer={vi.fn()}
onConnectHost={onConnectHost}
onSetLocation={onSetLocation}
orcaCloudAccess={{ state: 'signed-out' }}
/>
</TooltipProvider>
)
})
act(() => {
input().focus()
input().click()
})
const description = (label: string): string | null | undefined => {
const row = [...container.querySelectorAll('[role="option"]')].find((option) =>
option.textContent?.startsWith(label)
)
const id = row?.getAttribute('aria-describedby')
return id ? document.getElementById(id)?.textContent : null
}
expect(description('devbox')).toBe('devbox, project location not set. Press Enter to set it.')
expect(description('gpu-box')).toBe('gpu-box, not connected. Press Enter to connect.')
expect(description('Orca Cloud')).toBe('Orca Cloud, signed out. Press Enter to sign in.')
// A ready host needs no hint: Enter just picks it.
expect(description('Local Mac')).toBeNull()
// Enter on the Connect row connects (it used to fall through to Set location).
for (let i = 0; i < 8 && !activeText()?.startsWith('gpu-box'); i++) {
press('ArrowDown')
}
expect(activeText()).toMatch(/^gpu-box/)
press('Enter')
expect(onConnectHost).toHaveBeenCalledWith(expect.objectContaining({ label: 'gpu-box' }))
expect(onSetLocation).not.toHaveBeenCalled()
})
})
@@ -247,7 +247,12 @@ export default function RunTargetCombobox({
return
}
if (row.kind === 'needs-setup') {
setLocation(row.option)
// Enter does what the row's inline action does: Connect is not a Tab stop of its own.
if (row.option.connectAction && onConnectHost) {
void connectHost(row.option)
} else {
setLocation(row.option)
}
return
}
if (row.kind === 'orca-cloud') {
@@ -257,7 +262,7 @@ export default function RunTargetCombobox({
// Keyboard opening moves the arm into the submenu so arrows and Enter reach its rows.
openSubmenu(row.kind === 'recipes' ? 'recipes' : 'add-host', true)
},
[openSubmenu, rows, selectHost, selectOrcaCloud, setLocation]
[connectHost, onConnectHost, openSubmenu, rows, selectHost, selectOrcaCloud, setLocation]
)
const inSubmenu = submenu !== null && armedItemKey !== null
@@ -25,7 +25,8 @@ export function RunTargetRow({
busy = false,
onArm,
onCommit,
trailing
trailing,
description
}: {
icon: React.ReactNode
label: string
@@ -53,6 +54,8 @@ export function RunTargetRow({
busy?: boolean
/** Keyboard focus moved into this row's submenu: keep a lighter fill so the path stays visible. */
armedInSubmenu?: boolean
/** What Enter does when the row's inline action isn't a Tab stop of its own. */
description?: string
}): React.JSX.Element {
const t = useTranslate()
const hasDetail = Boolean(detailNode ?? detail)
@@ -65,6 +68,7 @@ export function RunTargetRow({
aria-busy={busy || undefined}
// option supports aria-haspopup but not aria-expanded; submenus are listboxes.
aria-haspopup={submenu ? 'listbox' : undefined}
aria-describedby={description ? `${optionId}-hint` : undefined}
data-armed={armed || undefined}
data-current={current ? 'true' : undefined}
onMouseDown={(event) => event.preventDefault()}
@@ -123,6 +127,11 @@ export function RunTargetRow({
</>
)}
{trailing}
{description ? (
<span id={`${optionId}-hint`} className="sr-only">
{description}
</span>
) : null}
{/* The committed row gets a check, not a second fill, so only the armed row is shaded. */}
{current ? (
<span className={cn('flex shrink-0 items-center pl-1.5', stacked ? 'self-center' : 'h-8')}>
@@ -1,4 +1,5 @@
import React from 'react'
import { orcaCloudRowHint } from './run-target-row-hints'
import { Cloud } from 'lucide-react'
import { Badge } from '@/components/ui/badge'
import { buttonVariants } from '@/components/ui/button'
@@ -318,6 +319,7 @@ export function RunTargetOrcaCloudRow({
busy={pending}
onArm={onArm}
onCommit={onSelect}
description={orcaCloudRowHint(access, t)}
trailing={<OrcaCloudMeta access={access} onAction={onBlockedAction} />}
/>
)
@@ -7,6 +7,8 @@ import { HostRowIcon, RunTargetRow } from './RunTargetComboboxRow'
import { ConnectHostButton, NeedsSetupHostIcon, SetLocationButton } from './RunTargetRowActions'
import { RecipesSubmenuRow, type RunTargetSubmenuArm } from './RunTargetSubmenus'
import { RunTargetOrcaCloudRow } from './RunTargetOrcaCloudRow'
import { needsSetupRowHint } from './run-target-row-hints'
import { useTranslate } from '@/i18n/use-translate'
import type { OrcaCloudRunTargetAccess } from './orca-cloud-run-target-access'
import type { EphemeralVmRecipeOption, RunTargetRowModel } from './run-target-options'
@@ -62,6 +64,7 @@ export default function RunTargetRowList({
onConnectHost: (option: NeedsSetupProjectHostOption) => void
onSetLocation: (option: NeedsSetupProjectHostOption) => void
}): React.JSX.Element {
const t = useTranslate()
return (
<>
{rows.map((row) => {
@@ -124,6 +127,11 @@ export default function RunTargetRowList({
optionId={optionId}
onArm={() => onArm(row.key, null)}
onCommit={() => onSetLocation(row.option)}
description={needsSetupRowHint(
row.option,
{ connect: canConnect, setLocation: canSetLocation, connecting },
t
)}
trailing={
hasConnect ? (
<ConnectHostButton
@@ -0,0 +1,84 @@
import type { Translate } from '@/i18n/use-translate'
import type { NeedsSetupProjectHostOption } from '@/lib/project-host-setup-options'
import type { OrcaCloudRunTargetAccess } from './orca-cloud-run-target-access'
// Run on rows are options inside one listbox: their inline actions ("Connect", "Set project
// location", "Sign in", …) are not separate Tab stops (DS-22). Each row's accessible description
// says what Enter does instead, so a screen-reader user hears the action the mouse user sees.
/** A host that can't run yet: Enter connects it, or sets the project location on it. */
export function needsSetupRowHint(
option: Pick<NeedsSetupProjectHostOption, 'label' | 'connectAction' | 'canSetLocation'>,
can: { connect: boolean; setLocation: boolean; connecting: boolean },
t: Translate
): string | undefined {
if (can.connecting) {
return undefined
}
if (option.connectAction && can.connect) {
return t(
'auto.components.new.workspace.RunTargetCombobox.hintConnect',
'{{host}}, not connected. Press Enter to connect.',
{ host: option.label }
)
}
if (option.canSetLocation && can.setLocation) {
return t(
'auto.components.new.workspace.RunTargetCombobox.hintSetLocation',
'{{host}}, project location not set. Press Enter to set it.',
{ host: option.label }
)
}
return undefined
}
/** Orca Cloud when picking it runs a fix first (sign in, plan, overage, payment). */
export function orcaCloudRowHint(
access: OrcaCloudRunTargetAccess,
t: Translate
): string | undefined {
switch (access.state) {
case 'signed-out':
return t(
'auto.components.new.workspace.RunTargetCombobox.hintSignIn',
'Orca Cloud, signed out. Press Enter to sign in.'
)
case 'no-plan':
if (!access.canManageBilling) {
return undefined
}
return access.lapsed
? t(
'auto.components.new.workspace.RunTargetCombobox.hintRenew',
'Orca Cloud, your Team plan ended. Press Enter to renew it.'
)
: t(
'auto.components.new.workspace.RunTargetCombobox.hintChoosePlan',
'Orca Cloud needs a Team plan. Press Enter to choose one.'
)
case 'out-of-hours':
if (!access.canManageBilling) {
return undefined
}
return access.cause === 'cap'
? t(
'auto.components.new.workspace.RunTargetCombobox.hintRaiseCap',
'Orca Cloud, spend cap reached. Press Enter to raise it.'
)
: t(
'auto.components.new.workspace.RunTargetCombobox.hintTurnOnOverage',
'Orca Cloud, sandbox hours used up. Press Enter to turn on overage.'
)
case 'payment-issue':
return access.canManageBilling
? t(
'auto.components.new.workspace.RunTargetCombobox.hintUpdatePayment',
'Orca Cloud, payment failed. Press Enter to update your payment method.'
)
: undefined
case 'loading':
case 'unknown':
case 'entitled':
return undefined
}
}
+9 -1
View File
@@ -16710,7 +16710,15 @@
"orcaCloudIdleSleep_other": "Sleeps after {{count}} minutes idle",
"orcaCloudAskAddHoursOnly": "Ask an owner or admin to add hours.",
"orcaCloudAskChoosePlan": "Ask an owner or admin to choose one.",
"orcaCloudAskRaiseSpendCap": "Ask an owner or admin to raise the spend cap."
"orcaCloudAskRaiseSpendCap": "Ask an owner or admin to raise the spend cap.",
"hintConnect": "{{host}}, not connected. Press Enter to connect.",
"hintSetLocation": "{{host}}, project location not set. Press Enter to set it.",
"hintSignIn": "Orca Cloud, signed out. Press Enter to sign in.",
"hintRenew": "Orca Cloud, your Team plan ended. Press Enter to renew it.",
"hintChoosePlan": "Orca Cloud needs a Team plan. Press Enter to choose one.",
"hintRaiseCap": "Orca Cloud, spend cap reached. Press Enter to raise it.",
"hintTurnOnOverage": "Orca Cloud, sandbox hours used up. Press Enter to turn on overage.",
"hintUpdatePayment": "Orca Cloud, payment failed. Press Enter to update your payment method."
},
"projectCombobox": {
"recentHeading": "Recent",