ui : fit wide image attachments to the message width

Attachment thumbnails used a fixed height with w-auto, so a wide image kept its aspect-driven width and, being flex-shrink-0 in a right-aligned bubble, overflowed to the left of the message row.

Cap the thumbnail with max-height and max-width instead of a fixed height so it scales down proportionally, and let it shrink outside the single-row carousel.

Assisted-by: pi:deepseek-ai/DeepSeek-V4.1-Flash
This commit is contained in:
Aleksander Grygier
2026-09-18 20:57:40 +02:00
parent d2f0ec4c1d
commit cca015c2d0
3 changed files with 11 additions and 3 deletions
@@ -41,6 +41,9 @@
}: Props = $props();
const scrollClasses = $derived(limitToSingleRow ? 'first:ml-4 last:mr-4' : '');
// Carousel items must keep their width; wrapped attachments (message bubbles)
// shrink so wide images fit the bubble instead of overflowing it
const layoutClasses = $derived(limitToSingleRow ? 'flex-shrink-0' : 'min-w-0');
function toMcpResourceAttachment(
extra: DatabaseMessageExtraMcpResource,
@@ -92,7 +95,7 @@
/>
{:else if item.isImage && item.preview}
<ChatAttachmentsListItemThumbnailImage
class="flex-shrink-0 cursor-pointer {className} {scrollClasses}"
class="{layoutClasses} cursor-pointer {className} {scrollClasses}"
height={imageHeight}
id={item.id}
{imageClass}
@@ -34,7 +34,7 @@
{/snippet}
<div
class="group relative overflow-hidden rounded-lg bg-muted shadow-lg dark:border dark:border-muted {className}"
class="group relative min-w-0 overflow-hidden rounded-lg bg-muted shadow-lg dark:border dark:border-muted {className}"
>
{#if onclick}
<button
@@ -54,7 +54,12 @@
{#if attachments && attachments.length > 0}
<div class="mb-2 max-w-[80%]">
<ChatAttachmentsList {attachments} imageHeight="h-40" readonly />
<ChatAttachmentsList
{attachments}
imageHeight="max-h-40"
imageWidth="w-auto max-w-full"
readonly
/>
</div>
{/if}