fix(site/src): announce copy confirmations to screen readers (#32696)

Five copy controls confirmed success only visually: an icon swap, new
button text, or tooltip text. They had no live region, so screen readers
did not announce the copy (WCAG 4.1.3). `CopyButton`,
`UserDropdownContent` and `AgentRow` already rendered a hidden
`role="status"` "Copied" span next to the control.

This exports that span from `CopyButton.tsx` as `CopiedStatus` and
renders it next to the five controls:

- **Template embed:** "Copy button Markdown"
- **CLI auth page:** "Copy session token"
- **Chat sharing popover:** "Copy link"
- **Remote diff panel:** branch name copy button
- **`CopyableValue`:** used for resource metadata, sensitive values and
the icons page

`CopyButton`, `UserDropdownContent` and `AgentRow` now use the same
component, with no change to their DOM.

Closes DEQ-629

| Ticket | UI surface |
|---|---|
| DEQ-629 | Template > Embed, CLI auth page, Agents chat share popover,
Agents remote diff branch copy, `CopyableValue` (workspace resource
metadata, icons page) |

No screenshots: the status text is visually hidden. Storybook pixel
diffs of `CopyableValue` and `CliAuthPageView` are identical to `main`
before and after clicking.

Verification:
- **Storybook:** each control renders an empty status region before the
click, and it reads "Copied" after.
- **Tests:** `CopyableValue` and `CliAuthPageView` get new tests. The
existing `ChatSharingPopover` and `TemplateEmbedPage` copy tests now
also check the status. Each fails without the change.
- **No test for `RemoteDiffPanel`:** it needs query mocking for its diff
fetch, and it renders the same `CopiedStatus` the other tests cover.
- **Checks:** `pnpm check` and `pnpm lint` pass.

Note (pre-existing, not changed here): in `UserDropdownContent`, the
status span sits inside the `DropdownMenuItem`, so "Copied" may become
part of that item's accessible name. Moving it is a separate change.

<details>
<summary>Decision log</summary>

- **Shared component:** review flagged pasting the same three-line span
into five more files (eight copies in total). `CopiedStatus` lives next
to `CopyButton`, which already owned the pattern. Adding it there needs
no new file, and every consumer imports from `components/`, so there are
no circular imports.
- **Sibling, not child:** the status is rendered next to the control,
not inside it, so it never changes the control's accessible name.
`sr-only` is absolutely positioned, so it does not affect `flex`/`gap`
layouts.
- **Many live regions on the icons page:** each `CopyableValue` mounts
an empty region. Only one is ever non-empty, because the next click
clears any earlier confirmation (`useClipboard`), the same as `AgentRow`
in lists.
- **Size:** about 30 non-test lines once whitespace from the new
fragments is ignored.

</details>

🤖 Generated by Coder Agents on behalf of @bartekgatzcoder.
This commit is contained in:
Bartek Gatz authored and GitHub committed 2026-11-25 10:02:51 +01:00
1 parent 8fae134458
commit cbbab78930
12 files changed
+157 -86

No files matched your search

+16 -3
View File
@@ -38,9 +38,22 @@ export const CopyButton: React.FC<CopyButtonProps> = ({
</TooltipTrigger>
<TooltipContent side={tooltipSide}>{label}</TooltipContent>
</Tooltip>
<span role="status" className="sr-only">
{showCopiedSuccess && "Copied"}
</span>
<CopiedStatus show={showCopiedSuccess} />
</>
);
};
type CopiedStatusProps = {
show: boolean;
};
/**
* Announces a successful copy to screen readers. Render it alongside the copy
* control before the copy happens, so the live region already exists when its
* text changes.
*/
export const CopiedStatus: React.FC<CopiedStatusProps> = ({ show }) => (
<span role="status" className="sr-only">
{show && "Copied"}
</span>
);
@@ -0,0 +1,19 @@
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderComponent } from "#/testHelpers/renderHelpers";
import { CopyableValue } from "./CopyableValue";
describe("CopyableValue", () => {
it("announces a successful copy", async () => {
const user = userEvent.setup();
renderComponent(
<CopyableValue value="crimson-cobra-7">crimson-cobra-7</CopyableValue>,
);
const status = screen.getByRole("status");
expect(status).toBeEmptyDOMElement();
await user.click(screen.getByRole("button", { name: "crimson-cobra-7" }));
expect(status).toHaveTextContent("Copied");
});
});
@@ -1,5 +1,6 @@
import { cn } from "cn";
import { useState } from "react";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import {
Tooltip,
TooltipContent,
@@ -36,53 +37,56 @@ export const CopyableValue: React.FC<CopyableValueProps> = ({
});
return (
<Tooltip
open={tooltipOpen}
onOpenChange={(shouldBeOpen) => {
// Always keep the tooltip open when in focus to handle issues when onOpenChange is unexpectedly false
if (!shouldBeOpen && isFocused) return;
setTooltipOpen(shouldBeOpen);
}}
>
<TooltipTrigger asChild>
<span
ref={clickableRef}
{...attrs}
className={cn("cursor-pointer", className)}
role={role ?? clickableProps.role}
tabIndex={tabIndex ?? clickableProps.tabIndex}
onClick={(event) => {
clickableProps.onClick(event);
onClick?.(event);
}}
onKeyDown={(event) => {
clickableProps.onKeyDown(event);
onKeyDown?.(event);
}}
onKeyUp={(event) => {
clickableProps.onKeyUp(event);
onKeyUp?.(event);
}}
onMouseEnter={() => {
setIsFocused(true);
setTooltipOpen(true);
}}
onMouseLeave={() => {
setTooltipOpen(false);
}}
onFocus={() => {
setIsFocused(true);
}}
onBlur={() => {
setTooltipOpen(false);
}}
>
{children}
</span>
</TooltipTrigger>
<TooltipContent side={side}>
{showCopiedSuccess ? "Copied!" : "Click to copy"}
</TooltipContent>
</Tooltip>
<>
<Tooltip
open={tooltipOpen}
onOpenChange={(shouldBeOpen) => {
// Always keep the tooltip open when in focus to handle issues when onOpenChange is unexpectedly false
if (!shouldBeOpen && isFocused) return;
setTooltipOpen(shouldBeOpen);
}}
>
<TooltipTrigger asChild>
<span
ref={clickableRef}
{...attrs}
className={cn("cursor-pointer", className)}
role={role ?? clickableProps.role}
tabIndex={tabIndex ?? clickableProps.tabIndex}
onClick={(event) => {
clickableProps.onClick(event);
onClick?.(event);
}}
onKeyDown={(event) => {
clickableProps.onKeyDown(event);
onKeyDown?.(event);
}}
onKeyUp={(event) => {
clickableProps.onKeyUp(event);
onKeyUp?.(event);
}}
onMouseEnter={() => {
setIsFocused(true);
setTooltipOpen(true);
}}
onMouseLeave={() => {
setTooltipOpen(false);
}}
onFocus={() => {
setIsFocused(true);
}}
onBlur={() => {
setTooltipOpen(false);
}}
>
{children}
</span>
</TooltipTrigger>
<TooltipContent side={side}>
{showCopiedSuccess ? "Copied!" : "Click to copy"}
</TooltipContent>
</Tooltip>
<CopiedStatus show={showCopiedSuccess} />
</>
);
};
@@ -9,6 +9,7 @@ import {
import { Link } from "react-router";
import type * as TypesGen from "#/api/typesGenerated";
import { CheckIcon } from "#/components/AnimatedIcons/Check";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import {
DropdownMenuItem,
DropdownMenuSeparator,
@@ -173,9 +174,7 @@ export const UserDropdownContent: React.FC<UserDropdownContentProps> = ({
) : (
<CopyIcon className="size-icon-xs! ml-auto" />
)}
<span role="status" className="sr-only">
{showCopiedSuccess && "Copied"}
</span>
<CopiedStatus show={showCopiedSuccess} />
</DropdownMenuItem>
</TooltipTrigger>
<TooltipContent side="left">
+2 -3
View File
@@ -26,6 +26,7 @@ import {
CollapsibleContent,
CollapsibleTrigger,
} from "#/components/Collapsible/Collapsible";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import {
DropdownMenu,
DropdownMenuContent,
@@ -688,9 +689,7 @@ export const AgentRow: React.FC<AgentRowProps> = ({
{showCopiedSuccess ? "Copied!" : copyLogsLabel}
</TooltipContent>
</Tooltip>
<span role="status" className="sr-only">
{showCopiedSuccess && "Copied"}
</span>
<CopiedStatus show={showCopiedSuccess} />
<DownloadSelectedAgentLogsButton
agentName={agent.name}
@@ -26,5 +26,8 @@ describe("ChatSharingPopover", () => {
expect(writeText).toHaveBeenCalledWith(
`${window.location.origin}/agents/${chatId}`,
);
expect(
screen.getAllByRole("status").map((status) => status.textContent),
).toContain("Copied");
});
});
@@ -17,6 +17,7 @@ import { CheckIcon } from "#/components/AnimatedIcons/Check";
import { Avatar } from "#/components/Avatar/Avatar";
import { AvatarData } from "#/components/Avatar/AvatarData";
import { Button } from "#/components/Button/Button";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import {
DropdownMenu,
DropdownMenuContent,
@@ -169,16 +170,19 @@ const CopyChatLinkButton: React.FC<CopyChatLinkButtonProps> = ({ chatId }) => {
const chatLink = new URL(`/agents/${chatId}`, window.location.origin).href;
return (
<Button
size="sm"
variant="outline"
onClick={() => {
void copyToClipboard(chatLink);
}}
>
{showCopiedSuccess ? <CheckIcon /> : <LinkIcon />}
{showCopiedSuccess ? "Copied" : "Copy link"}
</Button>
<>
<Button
size="sm"
variant="outline"
onClick={() => {
void copyToClipboard(chatLink);
}}
>
{showCopiedSuccess ? <CheckIcon /> : <LinkIcon />}
{showCopiedSuccess ? "Copied" : "Copy link"}
</Button>
<CopiedStatus show={showCopiedSuccess} />
</>
);
};
@@ -4,6 +4,7 @@ import { useQuery } from "react-query";
import { chatDiffContents } from "#/api/queries/chats";
import type * as TypesGen from "#/api/typesGenerated";
import { CheckIcon } from "#/components/AnimatedIcons/Check";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import {
Tooltip,
TooltipContent,
@@ -26,25 +27,28 @@ export { InlinePromptInput } from "../DiffViewer/CommentableDiffViewer";
const BranchCopyButton: React.FC<{ branch: string }> = ({ branch }) => {
const { copyToClipboard, showCopiedSuccess } = useClipboard();
return (
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
onClick={() => copyToClipboard(branch)}
aria-label={`Copy branch name: ${branch}`}
className="inline-flex shrink-0 cursor-pointer items-center justify-center rounded-sm bg-transparent p-0.5 text-content-secondary transition-colors hover:bg-surface-secondary hover:text-content-primary"
>
{showCopiedSuccess ? (
<CheckIcon className="size-3" />
) : (
<CopyIcon className="size-3" />
)}
</button>
</TooltipTrigger>
<TooltipContent side="bottom">
{showCopiedSuccess ? "Copied" : "Copy branch name"}
</TooltipContent>
</Tooltip>
<>
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
onClick={() => copyToClipboard(branch)}
aria-label={`Copy branch name: ${branch}`}
className="inline-flex shrink-0 cursor-pointer items-center justify-center rounded-sm bg-transparent p-0.5 text-content-secondary transition-colors hover:bg-surface-secondary hover:text-content-primary"
>
{showCopiedSuccess ? (
<CheckIcon className="size-3" />
) : (
<CopyIcon className="size-3" />
)}
</button>
</TooltipTrigger>
<TooltipContent side="bottom">
{showCopiedSuccess ? "Copied" : "Copy branch name"}
</TooltipContent>
</Tooltip>
<CopiedStatus show={showCopiedSuccess} />
</>
);
};
@@ -0,0 +1,21 @@
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { render } from "#/testHelpers/renderHelpers";
import { CliAuthPageView } from "./CliAuthPageView";
describe("CliAuthPageView", () => {
it("announces a copied session token", async () => {
const user = userEvent.setup();
const writeText = vi
.spyOn(navigator.clipboard, "writeText")
.mockResolvedValue();
render(<CliAuthPageView sessionToken="hunter2" />);
await user.click(
screen.getByRole("button", { name: "Copy session token" }),
);
expect(writeText).toHaveBeenCalledWith("hunter2");
expect(screen.getByRole("status")).toHaveTextContent("Copied");
});
});
@@ -1,6 +1,7 @@
import { CheckIcon, CopyIcon } from "lucide-react";
import { Link as RouterLink } from "react-router";
import { Button } from "#/components/Button/Button";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import { SignInLayout } from "#/components/SignInLayout/SignInLayout";
import { Spinner } from "#/components/Spinner/Spinner";
import { Welcome } from "#/components/Welcome/Welcome";
@@ -45,6 +46,7 @@ export const CliAuthPageView: React.FC<CliAuthPageViewProps> = ({
? "Session token copied!"
: "Copy session token"}
</Button>
<CopiedStatus show={clipboardState.showCopiedSuccess} />
<Button className="w-full" variant="subtle" asChild>
<RouterLink to="/workspaces">Go to workspaces</RouterLink>
@@ -173,6 +173,7 @@ describe("TemplateEmbedPage", () => {
await waitFor(() => {
expect(writeTextMock).toHaveBeenCalled();
expect(screen.getByRole("status")).toHaveTextContent("Copied");
});
const copiedText = writeTextMock.mock.calls[0][0] as string;
@@ -8,6 +8,7 @@ import type {
} from "#/api/typesGenerated";
import { ErrorAlert } from "#/components/Alert/ErrorAlert";
import { Button } from "#/components/Button/Button";
import { CopiedStatus } from "#/components/CopyButton/CopyButton";
import { InfoTooltip } from "#/components/InfoTooltip/InfoTooltip";
import { Label } from "#/components/Label/Label";
import { Link } from "#/components/Link/Link";
@@ -269,6 +270,7 @@ const ButtonPreview: React.FC<ButtonPreviewProps> = ({
{clipboard.showCopiedSuccess ? <CheckIcon /> : <CopyIcon />} Copy button
Markdown
</Button>
<CopiedStatus show={clipboard.showCopiedSuccess} />
</div>
);
};