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 ? (