Skip to content
TypeScript

fix(web): media preview centers its content and pins the close button (#17951)

maria0ecb25a8d45b
diff --git a/apps/web/src/components/chat/ExpandedImageDialog.tsx b/apps/web/src/components/chat/ExpandedImageDialog.tsx
index 0e641327a13..98c73d47c97 100644
--- a/apps/web/src/components/chat/ExpandedImageDialog.tsx
+++ b/apps/web/src/components/chat/ExpandedImageDialog.tsx
@@ -180,7 +180,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
variant="media"
showCloseButton={false}
bottomStickOnMobile={false}
- 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)]"
+ 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)]"
onKeyDown={onKeyDown}
initialFocus={closeButtonRef}
finalFocus={() => returnFocusTarget}
@@ -189,12 +189,24 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
}}
>
<DialogTitle className="sr-only">Expanded {mediaLabel} preview</DialogTitle>
+ {/* The stage keeps a fixed size, so the close button stays put whatever the media or caption. */}
+ <Button
+ type="button"
+ ref={closeButtonRef}
+ size="icon-sm"
+ variant="media-close"
+ className="absolute right-0 top-0 z-20"
+ onClick={onClose}
+ aria-label={`Close ${mediaLabel} preview`}
+ >
+ <XIcon />
+ </Button>
{preview.images.length > 1 && (
<Button
type="button"
size="icon"
variant="media-navigation"
- className="left-0 top-auto -bottom-12 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
+ className="left-0 top-auto bottom-0 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
aria-label="Previous media"
onClick={() => navigateImage(-1)}
>
@@ -202,18 +214,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
</Button>
)}
<MediaActions source={actionsSource}>
- <div className="relative isolate z-10 max-h-[92vh] max-w-[var(--media-width)]">
- <Button
- type="button"
- ref={closeButtonRef}
- size="icon-xs"
- variant="media-close"
- className="absolute right-0 -top-10 z-20"
- onClick={onClose}
- aria-label={`Close ${mediaLabel} preview`}
- >
- <XIcon />
- </Button>
+ <div className="relative isolate z-10 flex max-h-full max-w-[var(--media-width)] flex-col items-center">
{item.type === "video" ? (
<ExpandedVideo key={index} item={item} />
) : showingAccessibilityDetails ? (
@@ -241,7 +242,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
onError={() => setFailedImageSrc(item.src)}
/>
)}
- <div className="mt-2 flex max-w-[var(--media-width)] items-center justify-center gap-1.5 text-xs text-white/80">
+ <div className="mt-2 flex max-w-[var(--media-width)] items-center justify-center gap-1.5 text-xs text-white/80 max-sm:px-10">
<span className="truncate" aria-live="polite" aria-atomic="true">
{item.name}
{preview.images.length > 1 ? ` (${index + 1}/${preview.images.length})` : ""}
@@ -280,7 +281,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
type="button"
size="icon"
variant="media-navigation"
- className="right-0 top-auto -bottom-12 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
+ className="right-0 top-auto bottom-0 translate-y-0 sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2"
aria-label="Next media"
onClick={() => navigateImage(1)}
>