Skip to content

Commit 7f7daad

Browse files
shivamhwpPR Batch Testerclaude
authored
fix(web): screen readers say which thread a shortcut switched to (#23676)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a46f80e commit 7f7daad

10 files changed

Lines changed: 255 additions & 37 deletions

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
37653765
<ComposerContextActionsContext value={composerContextActions}>
37663766
<ComposerPromptEditor
37673767
draftKey={composerDraftTargetKey}
3768-
ariaLabel="Message"
3768+
// Switching threads lands focus here, so the label names the thread.
3769+
ariaLabel={activeThread ? `Message ${activeThread.title}` : "Message"}
37693770
suggestionListId={composerSuggestionListId}
37703771
activeSuggestionId={
37713772
composerSuggestionListVisible && activeComposerMenuItem

‎apps/web/src/components/chat/ModelPickerContent.tsx‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
useEnvironmentModelPreferences,
5353
useToggleEnvironmentModelFavorite,
5454
} from "~/hooks/useSettings";
55+
import { announce } from "~/lib/announce";
5556
import { cn } from "~/lib/utils";
5657
import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
5758
import { TooltipProvider } from "../ui/tooltip";
@@ -485,26 +486,26 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
485486
modelSlug: string,
486487
instanceId: ProviderInstanceId,
487488
additive = false,
488-
) => {
489+
): string | null => {
489490
if (getModelDisabledReason?.(instanceId, modelSlug)) {
490-
return;
491+
return null;
491492
}
492493
const options = modelOptionsByInstance.get(instanceId);
493494
if (!options) {
494-
return;
495+
return null;
495496
}
496497
const entry = instanceEntries.find((candidate) => candidate.instanceId === instanceId);
497498
if (!entry) {
498-
return;
499+
return null;
499500
}
500501
const resolvedModel = resolveSelectableModel(entry.driverKind, modelSlug, options);
501-
if (resolvedModel) {
502-
if (additive && onToggleModel) {
503-
onToggleModel(instanceId, resolvedModel);
504-
} else {
505-
onInstanceModelChange(instanceId, resolvedModel);
506-
}
502+
if (!resolvedModel) return null;
503+
if (additive && onToggleModel) {
504+
onToggleModel(instanceId, resolvedModel);
505+
} else {
506+
onInstanceModelChange(instanceId, resolvedModel);
507507
}
508+
return resolvedModel;
508509
};
509510

510511
const modelJumpShortcutContext = {
@@ -773,6 +774,10 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
773774
});
774775
setSearchQuery("");
775776
handleSelectInstance(next);
777+
announce(
778+
next === "favorites" ? "Favorites" : (entryByInstanceId.get(next)?.displayName ?? next),
779+
"model-picker",
780+
);
776781
return;
777782
}
778783
const jumpIndex = modelPickerJumpIndexFromCommand(command ?? "");
@@ -790,7 +795,12 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
790795
if (!model) {
791796
return;
792797
}
793-
handleModelSelect(model.slug, model.instanceId);
798+
const selectedSlug = handleModelSelect(model.slug, model.instanceId);
799+
if (selectedSlug === null) return;
800+
const name = flatModels.find(
801+
(item) => item.slug === selectedSlug && item.instanceId === model.instanceId,
802+
)?.name;
803+
announce(`Model: ${name ?? selectedSlug}`, "model-picker");
794804
};
795805

796806
return (

‎apps/web/src/components/chat/OpenInPicker.browser.test.tsx‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { AuthOrchestrationOperateScope, EnvironmentId, type EditorId } from "@t3tools/contracts";
22
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
3+
import { Cause } from "effect";
34
import { AsyncResult } from "effect/reactivity";
45
import { describe, expect, it, vi } from "vite-plus/test";
56

6-
import { act, render as renderUi } from "../../../test/render";
7+
import { act, fakeTimers, render as renderUi } from "../../../test/render";
78
import type { RemoteOpenState } from "../../remoteOpen";
89

910
const state = vi.hoisted(() => ({
@@ -181,3 +182,36 @@ describe("host editor access", () => {
181182
expect((await pressOpenFavorite()).defaultPrevented).toBe(false);
182183
});
183184
});
185+
186+
describe("open in editor announcement", () => {
187+
it("speaks only after the shortcut opened the editor, from the picker or the fallback", async () => {
188+
await using fixture = await setup();
189+
const { screen, renderPicker, pressOpenFavorite, FavoriteEditorFallback } = fixture;
190+
state.allowed.add(selected);
191+
await renderPicker();
192+
using _timers = fakeTimers();
193+
const regions = () => [...document.querySelectorAll('body > [aria-live="polite"]')];
194+
const spoken = async () => {
195+
await act(async () => vi.runAllTimers());
196+
return regions()
197+
.map((region) => region.textContent)
198+
.join("");
199+
};
200+
const refuse = () =>
201+
state.run.mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("No editor"))));
202+
203+
refuse();
204+
await pressOpenFavorite();
205+
expect(await spoken()).toBe("");
206+
await pressOpenFavorite();
207+
expect(await spoken()).toBe("Opened in VS Code");
208+
209+
for (const region of regions()) region.textContent = "";
210+
await act(async () => screen.rerender(<FavoriteEditorFallback />));
211+
refuse();
212+
await pressOpenFavorite();
213+
expect(await spoken()).toBe("");
214+
await pressOpenFavorite();
215+
expect(await spoken()).toBe("Opened in VS Code");
216+
});
217+
});

‎apps/web/src/components/chat/OpenInPicker.tsx‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
RustRoverIcon,
5959
WebStormIcon,
6060
} from "../JetBrainsIcons";
61+
import { announce } from "~/lib/announce";
6162
import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils";
6263
import { shellEnvironment } from "~/state/shell";
6364
import { useAtomCommand } from "~/state/use-atom-command";
@@ -240,29 +241,28 @@ export const OpenInPicker = memo(function OpenInPicker({
240241
const effectiveEditors = remote.mode === "local-exec" ? availableEditors : remoteCapableEditors;
241242
const [preferredEditor, setPreferredEditor] = usePreferredEditor(effectiveEditors);
242243

243-
const openInEditor = (editorId: EditorId | null) => {
244-
if (!openInCwd) return;
244+
const openInEditor = async (editorId: EditorId | null): Promise<boolean> => {
245+
if (!openInCwd) return false;
245246
const editor = editorId ?? preferredEditor;
246-
if (!editor) return;
247-
if (remote.mode === "remote-unavailable") return;
247+
if (!editor) return false;
248+
if (remote.mode === "remote-unavailable") return false;
248249
if (remote.mode === "remote-links") {
249250
const url = buildRemoteOpenUrl({
250251
editor,
251252
...remote.host,
252253
absolutePath: openInCwd,
253254
isFile: openInCwdIsFile,
254255
});
255-
if (url === undefined) return;
256+
if (url === undefined) return false;
256257
// Only record hint-seen/preferred when the shell actually accepted
257258
// the URL (an older desktop build can refuse the editor scheme).
258-
void openRemoteEditorUrl(url).then((opened) => {
259-
if (!opened) return;
260-
markRemoteHintSeen();
261-
setPreferredEditor(editor);
262-
});
263-
return;
259+
const opened = await openRemoteEditorUrl(url);
260+
if (!opened) return false;
261+
markRemoteHintSeen();
262+
setPreferredEditor(editor);
263+
return true;
264264
}
265-
if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return;
265+
if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false;
266266
const result = openInEditorMutation({
267267
environmentId,
268268
input: {
@@ -272,7 +272,7 @@ export const OpenInPicker = memo(function OpenInPicker({
272272
},
273273
});
274274
setPreferredEditor(editor);
275-
return result;
275+
return (await result)._tag === "Success";
276276
};
277277

278278
const openFavoriteEditorShortcutLabel = shortcutLabelForCommand(
@@ -293,7 +293,10 @@ export const OpenInPicker = memo(function OpenInPicker({
293293
return;
294294

295295
e.preventDefault();
296-
void openInEditor(preferredEditor);
296+
const label = editorLabelForPlatform(preferredEditor, navigator.platform);
297+
void openInEditor(preferredEditor).then((opened) => {
298+
if (opened) announce(`Opened in ${label}`);
299+
});
297300
};
298301
window.addEventListener("keydown", handler, true);
299302
return () => window.removeEventListener("keydown", handler, true);

‎apps/web/src/components/chat/OpenInPickerShortcut.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import type { EditorId, EnvironmentId, ResolvedKeybindingsConfig } from "@t3tool
22
import { useEffect } from "react";
33

44
import { usePreferredEditor } from "../../editorPreferences";
5+
import { editorLabelForPlatform } from "../../editorLabels";
56
import { isOpenFavoriteEditorShortcut } from "../../keybindings";
7+
import { announce } from "../../lib/announce";
68
import { useRemoteOpenState } from "../../remoteOpen";
79
import { shellEnvironment } from "../../state/shell";
810
import { useAtomCommand } from "../../state/use-atom-command";
@@ -31,12 +33,15 @@ export function useOpenFavoriteEditorShortcut({
3133
if (!openInCwd || !preferredEditor) return;
3234

3335
event.preventDefault();
36+
const label = editorLabelForPlatform(preferredEditor, navigator.platform);
3437
void openInEditorMutation({
3538
environmentId,
3639
input: {
3740
cwd: openInCwd,
3841
editor: preferredEditor,
3942
},
43+
}).then((result) => {
44+
if (result._tag === "Success") announce(`Opened in ${label}`);
4045
});
4146
};
4247
window.addEventListener("keydown", handler);

‎apps/web/src/components/chat/ProviderModelPicker.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
300300
terminalOpen={props.terminalOpen ?? false}
301301
onRequestClose={() => setIsMenuOpen(false)}
302302
{...(props.onOpenProviderSetup ? { onOpenProviderSetup: props.onOpenProviderSetup } : {})}
303-
{...(props.getModelDisabledReason
304-
? { getModelDisabledReason: props.getModelDisabledReason }
305-
: {})}
303+
getModelDisabledReason={(instanceId, model) =>
304+
props.disabled
305+
? "Model picker is disabled"
306+
: (props.getModelDisabledReason?.(instanceId, model) ?? null)
307+
}
306308
onInstanceModelChange={handleInstanceModelChange}
307309
/>
308310
{props.selectedModels === undefined ? (
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
3+
import { act, fakeTimers, render } from "../../../test/render";
4+
import { useThreadUndoNotice } from "../../hooks/showThreadUndoNotice";
5+
import { SidebarThreadUndoNotice } from "./SidebarThreadUndoNotice";
6+
7+
const spoken = () =>
8+
[...document.querySelectorAll('body > [aria-live="polite"]')]
9+
.map((region) => region.textContent)
10+
.join("");
11+
12+
describe("SidebarThreadUndoNotice", () => {
13+
it("speaks the notice, and drops it when the notice clears before it is spoken", async () => {
14+
using _notice = { [Symbol.dispose]: () => useThreadUndoNotice.setState({ notice: null }) };
15+
await using _screen = await render(<SidebarThreadUndoNotice />);
16+
using _timers = fakeTimers();
17+
const showSettled = () =>
18+
act(async () =>
19+
useThreadUndoNotice.setState({
20+
notice: { action: "Settled", count: 1, undo: async () => {} },
21+
}),
22+
);
23+
24+
await showSettled();
25+
await act(async () => vi.advanceTimersByTime(300));
26+
expect(spoken()).toMatch(/^Settled 1 thread, /);
27+
28+
await act(async () => useThreadUndoNotice.setState({ notice: null }));
29+
for (const region of document.querySelectorAll('body > [aria-live="polite"]')) {
30+
region.textContent = "";
31+
}
32+
await showSettled();
33+
await act(async () => useThreadUndoNotice.setState({ notice: null }));
34+
await act(async () => vi.advanceTimersByTime(300));
35+
expect(spoken()).toBe("");
36+
});
37+
});

‎apps/web/src/components/sidebar/SidebarThreadUndoNotice.tsx‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { useAtomValue } from "@effect/atom-react";
2+
import { useEffect } from "react";
23

34
import { undoLatestThreadAction, useThreadUndoNotice } from "../../hooks/showThreadUndoNotice";
45
import { shortcutLabelForCommand } from "../../keybindings";
6+
import { announce, cancelAnnouncement } from "../../lib/announce";
57
import { primaryServerKeybindingsAtom } from "../../state/server";
68
import { Alert, AlertDescription } from "../ui/alert";
79
import { InlineButton } from "../ui/button";
@@ -10,17 +12,25 @@ export function SidebarThreadUndoNotice() {
1012
const notice = useThreadUndoNotice((state) => state.notice);
1113
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
1214

13-
if (!notice) return null;
1415
const shortcut = shortcutLabelForCommand(keybindings, "thread.undo");
15-
const noun = `${notice.action === "Discarded" ? "draft" : "thread"}${notice.count === 1 ? "" : "s"}`;
16+
const undoLabel = shortcut ? `${shortcut} to undo` : "Undo";
17+
const summary = notice
18+
? `${notice.action} ${notice.count} ${notice.action === "Discarded" ? "draft" : "thread"}${notice.count === 1 ? "" : "s"}`
19+
: null;
20+
21+
// A live region that mounts already filled is skipped by screen readers, and settling
22+
// usually moves focus to the next thread at the same moment.
23+
useEffect(() => {
24+
if (summary) announce(`${summary}, ${undoLabel}`, "thread-undo-notice");
25+
else cancelAnnouncement("thread-undo-notice");
26+
}, [summary, undoLabel]);
27+
28+
if (!summary) return null;
1629

1730
return (
18-
<Alert role="status" variant="sidebar">
31+
<Alert role="group" variant="sidebar">
1932
<AlertDescription>
20-
{notice.action} {notice.count} {noun},{" "}
21-
<InlineButton onClick={undoLatestThreadAction}>
22-
{shortcut ? `${shortcut} to undo` : "Undo"}
23-
</InlineButton>
33+
{summary}, <InlineButton onClick={undoLatestThreadAction}>{undoLabel}</InlineButton>
2434
</AlertDescription>
2535
</Alert>
2636
);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
3+
import { fakeTimers } from "../../test/render";
4+
import { announce, cancelAnnouncement } from "./announce";
5+
6+
function spokenText() {
7+
return Array.from(document.querySelectorAll('[aria-live="polite"]'), (region) =>
8+
region.textContent?.trim(),
9+
).filter(Boolean);
10+
}
11+
12+
describe("announce", () => {
13+
it("waits for focus to settle, then speaks waiting messages together", () => {
14+
using _timers = fakeTimers();
15+
const composer = document.createElement("textarea");
16+
document.body.append(composer);
17+
using _composer = { [Symbol.dispose]: () => composer.remove() };
18+
19+
announce("Settled 1 thread, Ctrl+Z to undo");
20+
announce("Model: Claude Sonnet 5.5");
21+
vi.advanceTimersByTime(200);
22+
composer.focus();
23+
vi.advanceTimersByTime(200);
24+
expect(spokenText()).toEqual([]);
25+
26+
vi.advanceTimersByTime(50);
27+
expect(spokenText()).toEqual(["Settled 1 thread, Ctrl+Z to undo. Model: Claude Sonnet 5.5"]);
28+
});
29+
30+
it("speaks the same message twice in a row through the other region", () => {
31+
using _timers = fakeTimers();
32+
const regionTexts = () =>
33+
Array.from(document.querySelectorAll('[aria-live="polite"]'), (region) => region.textContent);
34+
35+
announce("Claude");
36+
vi.runAllTimers();
37+
const first = regionTexts();
38+
announce("Claude");
39+
vi.runAllTimers();
40+
41+
expect(regionTexts()).toEqual([...first].reverse());
42+
expect(regionTexts()).toContain("Claude");
43+
});
44+
45+
it("replaces a waiting message from the same source", () => {
46+
using _timers = fakeTimers();
47+
48+
announce("Settled 1 thread, Ctrl+Z to undo", "undo");
49+
announce("Opening in VS Code");
50+
announce("Settled 2 threads, Ctrl+Z to undo", "undo");
51+
vi.runAllTimers();
52+
53+
expect(spokenText()).toEqual(["Opening in VS Code. Settled 2 threads, Ctrl+Z to undo"]);
54+
55+
announce("Settled 1 thread, Ctrl+Z to undo", "undo");
56+
announce("Opening in Zed");
57+
cancelAnnouncement("undo");
58+
vi.runAllTimers();
59+
60+
expect(spokenText()).toEqual(["Opening in Zed"]);
61+
});
62+
});

0 commit comments

Comments
 (0)