The best way to control Claude Code, Codex and more from any computer or phone
fix(web): distinguish media Back from window close (#33125)
shivam committed
Nov 15, 2026 at 01:34 UTC
2afee52025283572212ff66e0fb3a23fc5b1b5d2
5 files changed
+44
-11
apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx
+6
-2
@@ -53,7 +53,9 @@ describe("ExpandedImageDialog", () => {
53
await userEvent.keyboard("{Tab}");
54
await userEvent.keyboard("{Enter}");
55
}
56
- await expect.element(page.getByRole("button", { name: "Close image preview" })).toHaveFocus();
56
+ await expect
57
+ .element(page.getByRole("button", { name: "Back, close image preview" }))
58
+ .toHaveFocus();
59
await userEvent.keyboard("{Escape}");
60
await expect.element(opener).toHaveFocus();
61
expect(opener.element().matches(":focus-visible")).toBe(c.focusVisible);
@@ -114,7 +116,9 @@ describe("ExpandedImageDialog", () => {
116
expect(onClose).not.toHaveBeenCalled();
117
118
// Focus returns to the popup's trigger and opens its tooltip; leave it for a plain control.
117
- (screen.getByRole("button", { name: "Close image preview" }).element() as HTMLElement).focus();
119
+ (
120
+ screen.getByRole("button", { name: "Back, close image preview" }).element() as HTMLElement
121
+ ).focus();
122
await userEvent.keyboard("{Escape}");
123
await vi.waitFor(() => expect(onClose).toHaveBeenCalledOnce());
124
});
apps/web/src/components/chat/ExpandedImageDialog.tsx
+13
-5
@@ -1,6 +1,12 @@
1
import { memo, useRef, useState, type ReactNode, type KeyboardEvent } from "react";
2
import { flushSync } from "react-dom";
3
-import { ChevronLeftIcon, ChevronRightIcon, XIcon, ImageIcon, TextIcon } from "lucide-react";
3
+import {
4
+ ArrowLeftIcon,
5
+ ChevronLeftIcon,
6
+ ChevronRightIcon,
7
+ ImageIcon,
8
+ TextIcon,
9
+} from "lucide-react";
10
import { Button } from "../ui/button";
11
import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
12
import type { ExpandedImageItem, ExpandedImagePreview } from "./ExpandedImagePreview";
@@ -174,6 +180,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
180
<DialogPopup
181
{...composerFloatingLayerProps}
182
variant="media"
183
+ mediaControlsPlacement="inside"
184
showCloseButton={false}
185
bottomStickOnMobile={false}
186
className="row-start-1 h-full max-h-[92vh] w-[92vw] max-w-[92vw] items-center justify-center overflow-visible [--media-width:92vw] [--media-height:min(calc((100vh-var(--native-titlebar-height,0px))*0.86),calc(100vh-var(--native-titlebar-height,0px)-160px))] sm:[--media-width:calc(92vw-96px)]"
@@ -188,13 +195,14 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
195
<Button
196
type="button"
197
ref={closeButtonRef}
191
- size="icon-sm"
198
+ size="sm"
199
variant="media-close"
193
- className="absolute right-0 top-0 z-20"
200
+ className="absolute left-0 top-0 z-20 max-[8rem]:left-1/2 max-[8rem]:-translate-x-1/2"
201
onClick={close}
195
- aria-label={`Close ${mediaLabel} preview`}
202
+ aria-label={`Back, close ${mediaLabel} preview`}
203
>
197
- <XIcon />
204
+ <ArrowLeftIcon aria-hidden="true" />
205
+ Back
206
</Button>
207
{preview.images.length > 1 && (
208
<Button
apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
+1
-1
@@ -164,7 +164,7 @@ it.each([false, true])(
164
await expect.element(page.getByText("second.png (2/2)", { exact: true })).toBeVisible();
165
await page.getByRole("button", { name: "Previous media", exact: true }).click();
166
await expect.element(page.getByText("first.png (1/2)", { exact: true })).toBeVisible();
167
- await page.getByRole("button", { name: "Close image preview", exact: true }).click();
167
+ await page.getByRole("button", { name: "Back, close image preview", exact: true }).click();
168
await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
169
await expect.element(page.getByText("Later", { exact: true })).toBeVisible();
170
},
apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
+1
-1
@@ -1477,7 +1477,7 @@ it("toggles a Mermaid attachment between diagram and source through the lazy pre
1477
expect(image?.alt).toBe("Mermaid diagram");
1478
expect(image?.naturalWidth).toBeGreaterThan(0);
1479
});
1480
- await page.getByRole("button", { name: "Close image preview" }).click();
1480
+ await page.getByRole("button", { name: "Back, close image preview" }).click();
1481
await vi.waitFor(() => expect(document.querySelector('[role="dialog"]')).toBeNull());
1482
await screen.getByRole("button", { name: "Show Mermaid source" }).click();
1483
await vi.waitFor(() => expect(screen.container.querySelector("pre")?.textContent).toBe(text));
apps/web/src/components/ui/dialog.tsx
+23
-2
@@ -1,8 +1,17 @@
1
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
2
import { useRender } from "@base-ui/react/use-render";
3
import { XIcon } from "lucide-react";
4
-import { type ComponentProps, createContext, type ReactNode, use, useRef, useState } from "react";
4
+import {
5
+ type ComponentProps,
6
+ type CSSProperties,
7
+ createContext,
8
+ type ReactNode,
9
+ use,
10
+ useRef,
11
+ useState,
12
+} from "react";
13
import { cn } from "~/lib/utils";
14
+import { useNativeTitlebarHeight } from "~/lib/windowControlsOverlay";
15
import { Button, type ButtonVariant } from "~/components/ui/button";
16
import {
17
DIALOG_BACKDROP_CLASS,
@@ -103,11 +112,13 @@ function DialogPopup({
112
showCloseButton = true,
113
bottomStickOnMobile = true,
114
variant = "default",
115
+ mediaControlsPlacement = "outside",
116
...props
117
}: DialogPrimitive.Popup.Props & {
118
showCloseButton?: boolean;
119
bottomStickOnMobile?: boolean;
120
variant?: "default" | "media";
121
+ mediaControlsPlacement?: "inside" | "outside";
122
}) {
123
const { popupRef, initialFocus } = useDialogActionInitialFocus();
124
const popup = useRender({
@@ -139,6 +150,8 @@ function DialogPopup({
150
</DialogPrimitive.Popup>
151
),
152
});
153
+ // macOS has no CSS window-controls overlay, so use the platform titlebar height.
154
+ const nativeTitlebarHeight = useNativeTitlebarHeight();
155
return (
156
<DialogPortal>
157
{/* Media opens from inside other overlays (a composer chip, a popover), so it sits above them. */}
@@ -147,8 +160,16 @@ function DialogPopup({
160
className={cn(
161
bottomStickOnMobile && "max-sm:grid-rows-[1fr_auto] max-sm:p-0 max-sm:pt-12",
162
variant === "media" &&
150
- "z-[60] grid-rows-1 place-items-center px-4 pb-6 pt-[calc(var(--native-titlebar-height,0px)+1.5rem)]",
163
+ "z-[60] grid-rows-1 place-items-center px-4 max-[8rem]:px-0 pb-6 pt-[calc(var(--media-dialog-titlebar-height,0px)+1.5rem)] [-webkit-app-region:no-drag]",
164
+ variant === "media" &&
165
+ mediaControlsPlacement === "inside" &&
166
+ "pt-[min(calc(var(--media-dialog-titlebar-height,0px)+1.5rem),50dvh)]",
167
)}
168
+ style={
169
+ variant === "media"
170
+ ? ({ "--media-dialog-titlebar-height": `${nativeTitlebarHeight}px` } as CSSProperties)
171
+ : undefined
172
+ }
173
>
174
{popup}
175
</DialogViewport>