@devries-cameron20 / t3code Mirror · read-only / commits / 27bf560fb2
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(web): image viewer close button stays clear of the window controls (#13919)

Otavio Salvador committed Oct 18, 2026 at 16:53 UTC 27bf560fb261396d99a9b92b23945477ad76cd1c
5 files changed +45 -18
apps/web/src/components/chat/ExpandedImageDialog.tsx
+1 -1
@@ -175,7 +175,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
175 variant="media"
176 showCloseButton={false}
177 bottomStickOnMobile={false}
178 - 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(86vh,calc(100vh-160px))] sm:[--media-width:calc(92vw-96px)]"
178 + 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)]"
179 onKeyDown={onKeyDown}
180 initialFocus={closeButtonRef}
181 finalFocus={() => returnFocusTarget}
apps/web/src/components/chat/ZoomableImage.tsx
+22 -8
@@ -1,7 +1,19 @@
1 import { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, type Ref } from "react";
2
3 +import {
4 + onWindowControlsOverlayGeometryChange,
5 + windowControlsOverlayHeight,
6 +} from "../../lib/windowControlsOverlay";
7 +
8 const MAX_ZOOM = 8;
9
10 +// The viewer lays out below the native caption strip so its controls never share a row with
11 +// the window buttons. ExpandedImageDialog and the media dialog viewport mirror this in CSS
12 +// through --native-titlebar-height.
13 +function readViewerSize() {
14 + return { width: window.innerWidth, height: window.innerHeight - windowControlsOverlayHeight() };
15 +}
16 +
17 export interface ZoomableImageHandle {
18 pan: (key: string) => boolean;
19 }
@@ -19,10 +31,7 @@ export function ZoomableImage({
31 }) {
32 const viewportRef = useRef<HTMLDivElement>(null);
33 const [naturalSize, setNaturalSize] = useState({ width: 0, height: 0 });
22 - const [windowSize, setWindowSize] = useState(() => ({
23 - width: window.innerWidth,
24 - height: window.innerHeight,
25 - }));
34 + const [viewerSize, setViewerSize] = useState(readViewerSize);
35 const [zoom, setZoom] = useState(1);
36 const zoomRef = useRef(1);
37 const anchorRef = useRef<{ x: number; y: number; clientX: number; clientY: number } | null>(null);
@@ -35,10 +44,10 @@ export function ZoomableImage({
44 } | null>(null);
45 const suppressClickRef = useRef(false);
46 const [dragging, setDragging] = useState(false);
38 - const maxHeight = Math.max(1, Math.min(windowSize.height * 0.86, windowSize.height - 160));
47 + const maxHeight = Math.max(1, Math.min(viewerSize.height * 0.86, viewerSize.height - 160));
48 const fit = Math.min(
49 1,
41 - (windowSize.width * 0.92 - (windowSize.width >= 640 ? 96 : 0)) / (naturalSize.width || 1),
50 + (viewerSize.width * 0.92 - (viewerSize.width >= 640 ? 96 : 0)) / (naturalSize.width || 1),
51 maxHeight / (naturalSize.height || 1),
52 );
53 const width = naturalSize.width * fit * zoom;
@@ -108,11 +117,16 @@ export function ZoomableImage({
117
118 useEffect(() => {
119 const resize = () => {
111 - setWindowSize({ width: window.innerWidth, height: window.innerHeight });
120 + setViewerSize(readViewerSize());
121 changeZoom(1);
122 };
123 window.addEventListener("resize", resize);
115 - return () => window.removeEventListener("resize", resize);
124 + // The caption strip can come and go around fullscreen without a matching resize event.
125 + const stopOverlayListener = onWindowControlsOverlayGeometryChange(resize);
126 + return () => {
127 + window.removeEventListener("resize", resize);
128 + stopOverlayListener();
129 + };
130 }, [changeZoom]);
131
132 useEffect(() => {
apps/web/src/components/ui/dialog.tsx
+1 -1
@@ -76,7 +76,7 @@ function DialogPopup({
76 className={cn(
77 bottomStickOnMobile && "max-sm:grid-rows-[1fr_auto] max-sm:p-0 max-sm:pt-12",
78 variant === "media" &&
79 - "z-[60] grid-rows-1 place-items-center px-4 py-6 [-webkit-app-region:no-drag]",
79 + "z-[60] grid-rows-1 place-items-center px-4 pb-6 pt-[calc(var(--native-titlebar-height,0px)+1.5rem)] [-webkit-app-region:no-drag]",
80 )}
81 >
82 <DialogPrimitive.Popup
apps/web/src/index.css
+1
@@ -149,6 +149,7 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
149 }
150
151 .wco {
152 + --native-titlebar-height: env(titlebar-area-height, 0px);
153 --workspace-topbar-height: max(40px, env(titlebar-area-height, 52px));
154 --workspace-controls-top: env(titlebar-area-y, 0px);
155 --workspace-controls-left: calc(env(titlebar-area-x, 0px) + 0.75rem);
apps/web/src/lib/windowControlsOverlay.ts
+20 -8
@@ -30,6 +30,25 @@ function getWindowControlsOverlay(): WindowControlsOverlayLike | null {
30 return (navigator as NavigatorWithWindowControlsOverlay).windowControlsOverlay ?? null;
31 }
32
33 +/** Height of the native caption strip drawn over the page, or 0 when the window has none. */
34 +export function windowControlsOverlayHeight(): number {
35 + const overlay = getWindowControlsOverlay();
36 + return overlay?.visible ? overlay.getTitlebarAreaRect().height : 0;
37 +}
38 +
39 +/** Calls `listener` when the native caption strip appears, disappears, or changes size. */
40 +export function onWindowControlsOverlayGeometryChange(listener: () => void): () => void {
41 + const overlay = getWindowControlsOverlay();
42 + if (!overlay) {
43 + return () => {};
44 + }
45 +
46 + overlay.addEventListener("geometrychange", listener);
47 + return () => {
48 + overlay.removeEventListener("geometrychange", listener);
49 + };
50 +}
51 +
52 export function syncDocumentWindowControlsOverlayClass(): () => void {
53 if (typeof document === "undefined") {
54 return () => {};
@@ -41,14 +60,7 @@ export function syncDocumentWindowControlsOverlayClass(): () => void {
60 };
61
62 update();
44 - if (!overlay) {
45 - return () => {};
46 - }
47 -
48 - overlay.addEventListener("geometrychange", update);
49 - return () => {
50 - overlay.removeEventListener("geometrychange", update);
51 - };
63 + return onWindowControlsOverlayGeometryChange(update);
64 }
65
66 function subscribeTitlebarArea(listener: () => void): () => void {