Skip to content

Commit 19251ba

Browse files
committed
fix(web): media preview centers its content and pins the close button
A long caption widened the media wrapper, so narrow images sat on its left edge and the close button, anchored to that wrapper, moved with every image. The dialog is now a fixed stage: media centers inside it and the close button stays in the stage's top-right corner.
1 parent 5f7294d commit 19251ba

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

‎apps/web/src/components/chat/ExpandedImageDialog.tsx‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
180180
variant="media"
181181
showCloseButton={false}
182182
bottomStickOnMobile={false}
183-
className="row-start-1 max-h-[92vh] w-[92vw] max-w-[92vw] items-center overflow-visible [--media-width:92vw] [--media-height:min(86vh,calc(100vh-160px))] sm:[--media-width:calc(92vw-96px)]"
183+
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)]"
184184
onKeyDown={onKeyDown}
185185
initialFocus={closeButtonRef}
186186
finalFocus={() => returnFocusTarget}
@@ -189,31 +189,32 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
189189
}}
190190
>
191191
<DialogTitle className="sr-only">Expanded {mediaLabel} preview</DialogTitle>
192+
{/* The stage keeps a fixed size, so the close button stays put whatever the media or caption. */}
193+
<Button
194+
type="button"
195+
ref={closeButtonRef}
196+
size="icon-sm"
197+
variant="media-close"
198+
className="absolute right-0 top-0 z-20"
199+
onClick={onClose}
200+
aria-label={`Close ${mediaLabel} preview`}
201+
>
202+
<XIcon />
203+
</Button>
192204
{preview.images.length > 1 && (
193205
<Button
194206
type="button"
195207
size="icon"
196208
variant="media-navigation"
197-
className="left-0 top-auto -bottom-12 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
209+
className="left-0 top-auto bottom-0 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
198210
aria-label="Previous media"
199211
onClick={() => navigateImage(-1)}
200212
>
201213
<ChevronLeftIcon className="size-5" />
202214
</Button>
203215
)}
204216
<MediaActions source={actionsSource}>
205-
<div className="relative isolate z-10 max-h-[92vh] max-w-[var(--media-width)]">
206-
<Button
207-
type="button"
208-
ref={closeButtonRef}
209-
size="icon-xs"
210-
variant="media-close"
211-
className="absolute right-0 -top-10 z-20"
212-
onClick={onClose}
213-
aria-label={`Close ${mediaLabel} preview`}
214-
>
215-
<XIcon />
216-
</Button>
217+
<div className="relative isolate z-10 flex max-h-full max-w-[var(--media-width)] flex-col items-center">
217218
{item.type === "video" ? (
218219
<ExpandedVideo key={index} item={item} />
219220
) : showingAccessibilityDetails ? (
@@ -280,7 +281,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
280281
type="button"
281282
size="icon"
282283
variant="media-navigation"
283-
className="right-0 top-auto -bottom-12 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
284+
className="right-0 top-auto bottom-0 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
284285
aria-label="Next media"
285286
onClick={() => navigateImage(1)}
286287
>

0 commit comments

Comments
 (0)