From 13e1f466f7bb4a4bf33e99c6c48bddc5cc04656c Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 26 Nov 2026 13:20:37 +0200 Subject: [PATCH] fix(site/src/pages/AgentsPage/components): keep hidden attachment controls tabbable and click-through (#31366) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On `main`, the attachment controls that show on hover or focus mishandle keyboard and pointer input: * The transcript's Download link hides with `visibility`, so Shift+Tab skips it. Tab from View reaches it only because focus on View shows it first. * The composer's hidden Remove button overhangs the top of its chip. Pointing at the overhang lands on the invisible button, which shows the buttons, and a click there hits Remove. * WebKit gives each hidden Download link a compositing layer for its backdrop blur. The composer's attachment card and the transcript's attachment frame now set custom properties from their own hover and `focus-within`, and their controls read them for opacity, pointer events and, on the Download link, the blur. Hidden controls stay in the tab order in both directions and take no pointer input. The blur applies only while the link shows and fades with it, so hidden links add no compositing layers: with four hidden links in view, WebKit composites 5 layers on `main` and 1 here. Devices without hover now show the composer's buttons at rest, as the transcript already did for the Download link. The new stories capture each focus state, including Shift+Tab onto the hidden Download link, Remove and Paste inline. > 🤖 This PR was created with the help of Coder Agents. --- .../components/AttachmentPreview.stories.tsx | 35 +++++++++++++++++++ .../components/AttachmentPreview.tsx | 7 ++-- .../ChatConversation/AttachmentBlocks.tsx | 6 ++-- .../ConversationTimeline.stories.tsx | 31 +++++++++------- 4 files changed, 61 insertions(+), 18 deletions(-) diff --git a/site/src/pages/AgentsPage/components/AttachmentPreview.stories.tsx b/site/src/pages/AgentsPage/components/AttachmentPreview.stories.tsx index 57143c56f2e..85c18df75e8 100644 --- a/site/src/pages/AgentsPage/components/AttachmentPreview.stories.tsx +++ b/site/src/pages/AgentsPage/components/AttachmentPreview.stories.tsx @@ -41,6 +41,41 @@ export const SingleImage: Story = { }, }; +// Focus on View, Paste inline or Remove shows Paste inline and Remove. The +// hidden buttons stay in the tab order, so Shift+Tab from the end of the page +// reaches Remove and then Paste inline. +export const ViewFocused: Story = { + args: (() => { + const file = createMockFile("clipboard.txt", "text/plain", 2048); + return { + attachments: [file], + uploadStates: new Map([ + [file, { status: "uploaded", fileId: "file-1" }], + ]), + previewUrls: new Map(), + textContents: new Map([[file, "Pasted text."]]), + }; + })(), + play: async () => { + await userEvent.tab(); + }, +}; + +export const PasteFocused: Story = { + args: ViewFocused.args, + play: async () => { + await userEvent.tab({ shift: true }); + await userEvent.tab({ shift: true }); + }, +}; + +export const RemoveFocused: Story = { + args: ViewFocused.args, + play: async () => { + await userEvent.tab({ shift: true }); + }, +}; + export const MultipleImages: Story = { args: (() => { const files = [ diff --git a/site/src/pages/AgentsPage/components/AttachmentPreview.tsx b/site/src/pages/AgentsPage/components/AttachmentPreview.tsx index 75709517013..511469bcecb 100644 --- a/site/src/pages/AgentsPage/components/AttachmentPreview.tsx +++ b/site/src/pages/AgentsPage/components/AttachmentPreview.tsx @@ -139,7 +139,8 @@ export const AttachmentPreview: React.FC<{ // Key combines file metadata with index as a fallback for // duplicate names. Acceptable for a small, append-only list. key={`${file.name}-${file.size}-${file.lastModified}-${index}`} - className="group relative" + // Not `group-focus-within`, which slows WebKit focus changes. + className="relative [--actions-opacity:0] [--actions-pointer-events:none] hover:[--actions-opacity:1] hover:[--actions-pointer-events:auto] focus-within:[--actions-opacity:1] focus-within:[--actions-pointer-events:auto] [@media(hover:none)]:[--actions-opacity:1] [@media(hover:none)]:[--actions-pointer-events:auto]" > {isRasterImageMediaType(file.type) && previewUrl ? (