Skip to content

Commit 75664b7

Browse files
committed
fix(chat): keep the remove badge anchored to the file card
The card wrapper had no width cap, so it sized to the filename's max-content width while the card itself capped at 220px. The remove badge is positioned against that wrapper, so a long filename stranded it far to the right of the card it belongs to. Moves the cap onto the wrapper and lets the card fill it.
1 parent 1c0e82a commit 75664b7

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/attached-files-list/attached-files-list.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ describe('AttachedFilesList', () => {
6767
expect(container.querySelector('img')).toBeNull()
6868
})
6969

70+
it('caps the card wrapper so a long filename cannot strand the remove badge', () => {
71+
// The badge is positioned against this wrapper. Without a cap here the wrapper
72+
// stretches to the filename's max-content width while the card stays 220px, and
73+
// the badge drifts off to the right of the card.
74+
render([file({ name: '9bacf973-cd64-437b-be12-58be9f2c1a4d-very-long-name.pdf' })])
75+
76+
const wrapper = container.querySelector('button')?.parentElement
77+
expect(wrapper?.className).toContain('max-w-[min(220px,100%)]')
78+
})
79+
7080
it('drops the image and reveals the type icon when the preview fails to decode', () => {
7181
render([file({ name: 'photo.heic', type: 'image/heic', previewUrl: '/api/files/serve/x' })])
7282

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/attached-files-list/attached-files-list.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,25 @@ const AttachedFileChip = React.memo(function AttachedFileChip({
5454

5555
return (
5656
<Tooltip.Root>
57-
<div className={cn('group relative', isMedia ? 'flex-shrink-0' : 'min-w-0')}>
57+
{/* The width cap lives here, not on the button: this wrapper anchors the remove
58+
badge, and sizing it to the button's uncapped max-content width would strand
59+
the badge far to the right of a long filename. */}
60+
<div
61+
className={cn(
62+
'group relative',
63+
isMedia ? 'flex-shrink-0' : 'min-w-0 max-w-[min(220px,100%)]'
64+
)}
65+
>
5866
<Tooltip.Trigger asChild>
5967
<button
6068
type='button'
6169
className={cn(
6270
CHIP_SURFACE,
6371
isMedia
6472
? 'w-[48px] overflow-hidden'
65-
: // Capped at 220px but never wider than the composer, so a long filename
66-
// truncates on a narrow viewport instead of overflowing the shell.
67-
'flex max-w-[min(220px,100%)] items-center gap-2 py-2 pr-3 pl-2'
73+
: // Fills the capped wrapper, so the filename truncates rather than
74+
// widening the card past the badge it is anchored to.
75+
'flex w-full items-center gap-2 py-2 pr-3 pl-2'
6876
)}
6977
onClick={() => onFileClick(file)}
7078
>

0 commit comments

Comments
 (0)