Skip to content

Commit 7389423

Browse files
fix(web): screen readers hear the add-project submit shortcut (#32576)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e509db3 commit 7389423

3 files changed

Lines changed: 61 additions & 9 deletions

File tree

‎apps/web/src/components/CommandPalette.composition.browser.test.tsx‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import { describe, expect, it, vi } from "vite-plus/test";
22
import { page, userEvent } from "vite-plus/test/browser";
33
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
44
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
5+
import { AuthOrchestrationOperateScope, AuthSourceControlWriteScope } from "@t3tools/contracts";
56
import { act, render } from "../../test/render";
67
import { CommandPalette } from "./CommandPalette";
78
import { openCommandPalette } from "../commandPaletteBus";
89
import { primaryServerKeybindingsAtom } from "../state/server";
910

11+
const scopes = vi.hoisted(() => ({ denied: undefined as string | undefined }));
12+
const setup = (deniedScope?: string) => {
13+
scopes.denied = deniedScope;
14+
};
15+
1016
vi.mock("@effect/atom-react", async (original) => ({
1117
...(await original<typeof import("@effect/atom-react")>()),
1218
useAtomValue: (atom: unknown) =>
@@ -85,7 +91,7 @@ vi.mock("../state/queries", async (original) => ({
8591
}));
8692
vi.mock("../state/session", async (original) => ({
8793
...(await original<typeof import("../state/session")>()),
88-
useEnvironmentScope: () => true,
94+
useEnvironmentScope: (_environmentId: unknown, scope: string) => scope !== scopes.denied,
8995
readEnvironmentScope: () => true,
9096
}));
9197
vi.mock("../state/filesystem", async (original) => ({
@@ -106,6 +112,7 @@ describe.each(["repository", "folder", "destination"] as const)("add-project %s"
106112
{ isComposing: true, keyCode: 13 },
107113
{ isComposing: false, keyCode: 229 },
108114
])("keeps Enter in the input during composition: %j", async (composition) => {
115+
setup();
109116
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
110117
await act(() => openCommandPalette({ open: "add-project" }));
111118
await page.getByText(step === "folder" ? "Local folder" : "Git URL", { exact: true }).click();
@@ -135,7 +142,44 @@ describe.each(["repository", "folder", "destination"] as const)("add-project %s"
135142
});
136143
});
137144

145+
it.each([
146+
{ step: "folder", source: "Local folder", keys: "", description: /^(?!.*(Ctrl|⌘)).*Add.*Enter/ },
147+
{
148+
step: "highlighted folder",
149+
source: "Local folder",
150+
keys: "{ArrowDown}",
151+
description: /Add.*(Ctrl|⌘) Enter/,
152+
},
153+
{ step: "repository", source: "Git URL", keys: "", description: /Continue.*Enter/ },
154+
{ step: "new project", source: "New project", keys: "", description: /Create.*Enter/ },
155+
{
156+
step: "permission-blocked folder",
157+
source: "Local folder",
158+
keys: "",
159+
deniedScope: AuthOrchestrationOperateScope,
160+
description: "This connection cannot add projects.",
161+
},
162+
{
163+
step: "permission-blocked destination",
164+
source: "Git URL",
165+
keys: "https://example.com/team/project.git{Enter}",
166+
deniedScope: AuthSourceControlWriteScope,
167+
description: "This connection needs permission to write source control and add projects.",
168+
},
169+
])(
170+
"tells screen readers how to submit the $step step",
171+
async ({ source, keys, deniedScope, description }) => {
172+
setup(deniedScope);
173+
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
174+
await act(() => openCommandPalette({ open: "add-project" }));
175+
await page.getByText(source, { exact: true }).click();
176+
if (keys) await userEvent.keyboard(keys);
177+
await expect.element(page.getByRole("combobox")).toHaveAccessibleDescription(description);
178+
},
179+
);
180+
138181
it("keeps the caret in place when an edit briefly makes the folder path not a path", async () => {
182+
setup();
139183
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
140184
await act(() => openCommandPalette({ open: "add-project" }));
141185
await page.getByText("Local folder", { exact: true }).click();

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { openThreadFind } from "./chat/threadFindStore";
8282
import {
8383
useDeferredValue,
8484
useEffect,
85+
useId,
8586
useReducer,
8687
useRef,
8788
useState,
@@ -2784,9 +2785,17 @@ function OpenCommandPaletteDialog(props: {
27842785
await handleAddProject(pickedPath);
27852786
};
27862787

2788+
const submitButtonId = useId();
2789+
const browseSubmitLabel =
2790+
isCloneDestinationStep && !canCloneProject
2791+
? "This connection needs permission to write source control and add projects."
2792+
: canCreateProject
2793+
? `${submitActionLabel} (${addShortcutLabel})`
2794+
: "This connection cannot add projects.";
27872795
const inputAccessory =
27882796
newProjectFlow !== null ? (
27892797
<CommandPaletteSubmitButton
2798+
id={submitButtonId}
27902799
label={isCreatingNewProject ? "Creating" : "Create"}
27912800
shortcutLabel={createShortcutLabel}
27922801
ariaLabel={`Create (${createShortcutLabel})`}
@@ -2798,6 +2807,7 @@ function OpenCommandPaletteDialog(props: {
27982807
/>
27992808
) : addProjectCloneFlow?.step === "repository" ? (
28002809
<CommandPaletteSubmitButton
2810+
id={submitButtonId}
28012811
label={isRemoteProjectPending ? "Working" : remoteProjectButtonLabel}
28022812
shortcutLabel="Enter"
28032813
ariaLabel={`${remoteProjectButtonLabel ?? "Continue"} (Enter)`}
@@ -2809,16 +2819,11 @@ function OpenCommandPaletteDialog(props: {
28092819
/>
28102820
) : isBrowsing ? (
28112821
<CommandPaletteSubmitButton
2822+
id={submitButtonId}
28122823
label={isCloneDestinationStep && isRemoteProjectPending ? "Cloning" : submitActionLabel}
28132824
shortcutLabel={addShortcutLabel}
2814-
ariaLabel={`${submitActionLabel} (${addShortcutLabel})`}
2815-
tooltip={
2816-
isCloneDestinationStep && !canCloneProject
2817-
? "This connection needs permission to write source control and add projects."
2818-
: canCreateProject
2819-
? `${submitActionLabel} (${addShortcutLabel})`
2820-
: "This connection cannot add projects."
2821-
}
2825+
ariaLabel={browseSubmitLabel}
2826+
tooltip={browseSubmitLabel}
28222827
disabled={
28232828
!canCreateProject ||
28242829
!canCreateProjectInEnvironment(browseEnvironment?.connection.phase) ||
@@ -2886,6 +2891,7 @@ function OpenCommandPaletteDialog(props: {
28862891
})
28872892
: undefined,
28882893
placeholder: inputPlaceholder,
2894+
"aria-describedby": inputAccessory ? submitButtonId : undefined,
28892895
...(isSubmenu
28902896
? {
28912897
startAddon: (

‎apps/web/src/components/CommandPaletteAddProject.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function sourceControlHostIcon(
3434

3535
/** The input's trailing submit button for the add-project, clone, and new-project flows. */
3636
export function CommandPaletteSubmitButton(props: {
37+
readonly id: string;
3738
readonly label: ReactNode;
3839
readonly shortcutLabel: string;
3940
readonly ariaLabel: string;
@@ -46,6 +47,7 @@ export function CommandPaletteSubmitButton(props: {
4647
<TooltipTrigger
4748
render={
4849
<Button
50+
id={props.id}
4951
variant="outline"
5052
size="xs"
5153
className="absolute inset-e-2.5 top-1/2 -translate-y-1/2"

0 commit comments

Comments
 (0)