From cbbab78930f3ef910cfbd4a84dbaef3d3dc201e7 Mon Sep 17 00:00:00 2001 From: Bartek Gatz Date: Wed, 25 Nov 2026 10:02:51 +0100 Subject: [PATCH] fix(site/src): announce copy confirmations to screen readers (#32696) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.
Decision log - **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.
🤖 Generated by Coder Agents on behalf of @bartekgatzcoder. --- site/src/components/CopyButton/CopyButton.tsx | 19 +++- .../CopyableValue/CopyableValue.test.tsx | 19 ++++ .../CopyableValue/CopyableValue.tsx | 100 +++++++++--------- .../UserDropdown/UserDropdownContent.tsx | 5 +- site/src/modules/resources/AgentRow.tsx | 5 +- .../components/ChatSharingPopover.test.tsx | 3 + .../components/ChatSharingPopover.tsx | 24 +++-- .../components/DiffViewer/RemoteDiffPanel.tsx | 42 ++++---- .../CliAuthPage/CliAuthPageView.test.tsx | 21 ++++ .../src/pages/CliAuthPage/CliAuthPageView.tsx | 2 + .../TemplateEmbedPage.test.tsx | 1 + .../TemplateEmbedPageView.tsx | 2 + 12 files changed, 157 insertions(+), 86 deletions(-) create mode 100644 site/src/components/CopyableValue/CopyableValue.test.tsx create mode 100644 site/src/pages/CliAuthPage/CliAuthPageView.test.tsx diff --git a/site/src/components/CopyButton/CopyButton.tsx b/site/src/components/CopyButton/CopyButton.tsx index 9c37e3d4e05..a93aa4d1fd4 100644 --- a/site/src/components/CopyButton/CopyButton.tsx +++ b/site/src/components/CopyButton/CopyButton.tsx @@ -38,9 +38,22 @@ export const CopyButton: React.FC = ({ {label} - - {showCopiedSuccess && "Copied"} - + ); }; + +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 = ({ show }) => ( + + {show && "Copied"} + +); diff --git a/site/src/components/CopyableValue/CopyableValue.test.tsx b/site/src/components/CopyableValue/CopyableValue.test.tsx new file mode 100644 index 00000000000..56be117388b --- /dev/null +++ b/site/src/components/CopyableValue/CopyableValue.test.tsx @@ -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( + crimson-cobra-7, + ); + + const status = screen.getByRole("status"); + expect(status).toBeEmptyDOMElement(); + await user.click(screen.getByRole("button", { name: "crimson-cobra-7" })); + + expect(status).toHaveTextContent("Copied"); + }); +}); diff --git a/site/src/components/CopyableValue/CopyableValue.tsx b/site/src/components/CopyableValue/CopyableValue.tsx index a692210f07e..724527d883b 100644 --- a/site/src/components/CopyableValue/CopyableValue.tsx +++ b/site/src/components/CopyableValue/CopyableValue.tsx @@ -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 = ({ }); return ( - { - // Always keep the tooltip open when in focus to handle issues when onOpenChange is unexpectedly false - if (!shouldBeOpen && isFocused) return; - setTooltipOpen(shouldBeOpen); - }} - > - - { - 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} - - - - {showCopiedSuccess ? "Copied!" : "Click to copy"} - - + <> + { + // Always keep the tooltip open when in focus to handle issues when onOpenChange is unexpectedly false + if (!shouldBeOpen && isFocused) return; + setTooltipOpen(shouldBeOpen); + }} + > + + { + 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} + + + + {showCopiedSuccess ? "Copied!" : "Click to copy"} + + + + ); }; diff --git a/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdownContent.tsx b/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdownContent.tsx index 465a9cda042..3c7c1a8936d 100644 --- a/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdownContent.tsx +++ b/site/src/modules/dashboard/Navbar/UserDropdown/UserDropdownContent.tsx @@ -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 = ({ ) : ( )} - - {showCopiedSuccess && "Copied"} - + diff --git a/site/src/modules/resources/AgentRow.tsx b/site/src/modules/resources/AgentRow.tsx index 008c5cbe0f7..016b2c274cc 100644 --- a/site/src/modules/resources/AgentRow.tsx +++ b/site/src/modules/resources/AgentRow.tsx @@ -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 = ({ {showCopiedSuccess ? "Copied!" : copyLogsLabel} - - {showCopiedSuccess && "Copied"} - + { expect(writeText).toHaveBeenCalledWith( `${window.location.origin}/agents/${chatId}`, ); + expect( + screen.getAllByRole("status").map((status) => status.textContent), + ).toContain("Copied"); }); }); diff --git a/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx b/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx index 7a3a222ac7a..3eee70790f4 100644 --- a/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx +++ b/site/src/pages/AgentsPage/components/ChatSharingPopover.tsx @@ -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 = ({ chatId }) => { const chatLink = new URL(`/agents/${chatId}`, window.location.origin).href; return ( - + <> + + + ); }; diff --git a/site/src/pages/AgentsPage/components/DiffViewer/RemoteDiffPanel.tsx b/site/src/pages/AgentsPage/components/DiffViewer/RemoteDiffPanel.tsx index 1cda1e089eb..0ea88a2cf13 100644 --- a/site/src/pages/AgentsPage/components/DiffViewer/RemoteDiffPanel.tsx +++ b/site/src/pages/AgentsPage/components/DiffViewer/RemoteDiffPanel.tsx @@ -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 ( - - - - - - {showCopiedSuccess ? "Copied" : "Copy branch name"} - - + <> + + + + + + {showCopiedSuccess ? "Copied" : "Copy branch name"} + + + + ); }; diff --git a/site/src/pages/CliAuthPage/CliAuthPageView.test.tsx b/site/src/pages/CliAuthPage/CliAuthPageView.test.tsx new file mode 100644 index 00000000000..67f95d53c92 --- /dev/null +++ b/site/src/pages/CliAuthPage/CliAuthPageView.test.tsx @@ -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(); + + await user.click( + screen.getByRole("button", { name: "Copy session token" }), + ); + + expect(writeText).toHaveBeenCalledWith("hunter2"); + expect(screen.getByRole("status")).toHaveTextContent("Copied"); + }); +}); diff --git a/site/src/pages/CliAuthPage/CliAuthPageView.tsx b/site/src/pages/CliAuthPage/CliAuthPageView.tsx index 6d2af78d55d..445e20f72df 100644 --- a/site/src/pages/CliAuthPage/CliAuthPageView.tsx +++ b/site/src/pages/CliAuthPage/CliAuthPageView.tsx @@ -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 = ({ ? "Session token copied!" : "Copy session token"} + + ); };