Examples

Open a local preview or remove an attachment. The strip scrolls within its column on a phone.

Open and remove attachments

Eight attachments ready

Read-only attachments

Without action callbacks, an overflowing strip is reached and scrolled with the keyboard.

notes-1.txt
notes-2.txt
notes-3.txt
notes-4.txt
notes-5.txt
notes-6.txt

Documentation

The pending-attachment strip above a chat composer: image thumbnails and file tiles, each with a floating remove button, scrolling horizontally through the library Scroller when they overflow. Renders nothing while there are no attachments.

The scroll region is named Pending attachments. In a read-only row with overflowing content, Tab reaches the region and the arrow keys scroll the chips. When chips have open or remove actions, those controls provide the keyboard route instead.

Try the interactive example.

Remove buttons identify their attachment by filename. Images and videos without a filename use their kind and position, such as “Remove image 2 of 3”. Open and remove callbacks retain their original attachment and ID payloads.

File tiles keep the end of the filename visible when they truncate it. Hover, focus, or touch and hold the tile to read the complete name. A regular tap still opens the file when an open callback is provided.

Usage

<script>
  import { AttachmentChipRow } from '@juspay/svelte-ui-components';
</script>

<AttachmentChipRow
  {images}
  {files}
  imageTooltip={(image) => image.filename ?? ''}
  onremoveimage={(id) => removeImage(id)}
  onremovefile={(id) => removeFile(id)}
/>

Props

Prop Type Required Default Description
images AttachmentChipImage[] No [] { id, thumbnailData, filename? } — thumbnailData is the img src.
files AttachmentChipFile[] No [] { id, filename }.
videos AttachmentChipVideo[] No [] { id, thumbnailData?, filename? } — a poster tile with a play badge; a plain dark tile without a poster.
onremoveimage (id: string) => void No - Fires with the chip's id. Omit for a read-only row (no remove buttons).
onremovefile (id: string) => void No - Fires with the chip's id. Omit for a read-only row.
onremovevideo (id: string) => void No - Fires with the chip's id. Omit for a read-only row.
onopenimage (image: AttachmentChipImage) => void No - Makes the image tile a real button; fires on click (e.g. open a lightbox).
onopenvideo (video: AttachmentChipVideo) => void No - Makes the video tile a real button; fires on click (e.g. play the video).
onopenfile (file: AttachmentChipFile) => void No - Makes the file tile a real button; fires on click.
imageTooltip (image: AttachmentChipImage) => string No - Tooltip text for an image chip.
videoTooltip (video: AttachmentChipVideo) => string No - Tooltip text for a video chip.
removeIcon Snippet No - Glyph inside the remove button. Built-in cross when omitted.
fileIcon Snippet No - Glyph on a file tile. Built-in document when omitted.
testId string No - On the Scroller; chips get -image-<id> / -file-<id>.
ariaLabel string No 'Pending attachments' Accessible name of the attachment strip; distinguish independent strips on the same page.
classes string No - Class string passed through to the Scroller.

CSS Variables

Variable Default Description
--attachment-chip-row-gap 0.5rem Gap between chips.
--attachment-chip-row-chip-size 4.5rem Chip width and height.
--attachment-chip-row-chip-border-radius 0.5rem Chip corner rounding.
--attachment-chip-row-chip-background #ffffff Chip background.
--attachment-chip-row-chip-padding-top 0.25rem Headroom for the remove button.
--attachment-chip-row-remove-size 1.25rem (1.125rem <768px) Remove button size.
--attachment-chip-row-remove-offset 0 Remove button inset from the chip's padded corner — the chip's own top/right padding hosts the straddle, so a clipping ancestor never cuts the button off.
--attachment-chip-row-chip-padding-right 0.25rem Right padding the remove button straddles into.
--attachment-chip-row-remove-background #18181b Remove button disc color (self-contained — readable on both themes).
--attachment-chip-row-remove-color #ffffff Remove glyph color.
--attachment-chip-row-remove-hover-background #3f3f46 Remove button hover disc.
--attachment-chip-row-thumb-img-width 100% Width of an image chip's thumbnail <img>.
--attachment-chip-row-thumb-img-height 100% Height of an image chip's thumbnail <img>.
--attachment-chip-row-thumb-img-fit cover object-fit of an image chip's thumbnail <img>.
--attachment-chip-row-file-tile-gap 0.25rem Gap between the glyph and filename inside a file tile.
--attachment-chip-row-file-tile-padding 0.25rem 2px Padding inside a file tile.
--attachment-chip-row-file-tile-box-shadow 0 2px 0.25rem rgb(0 0 0 / 10%) Box shadow on a file tile.
--attachment-chip-row-file-name-font-weight 400 Font weight of a file chip's filename text.
--attachment-chip-row-file-name-letter-spacing normal Letter spacing of a file chip's filename text.
--attachment-chip-row-file-name-line-height 1.25rem Line height of a file chip's filename text.
--attachment-chip-row-remove-ring 1.5px solid #ffffff Ring separating the disc from the thumbnail beneath.
--attachment-chip-row-remove-box-shadow 0 1px 3px rgb(0 0 0 / 30%) Remove button shadow.
--attachment-chip-row-video-tile-background #18181b Video tile ground (behind/without a poster).
--attachment-chip-row-play-glyph-size 1.25rem Play badge glyph size.
--attachment-chip-row-play-glyph-color #ffffff Play badge glyph color.
--attachment-chip-row-play-glyph-shadow drop-shadow(0 1px 2px rgb(0 0 0 / 45%)) Play badge legibility shadow over bright posters.
--attachment-chip-row-remove-border-radius 999px Remove button rounding.
--attachment-chip-row-remove-glyph-size 0.625rem Built-in cross size.
--attachment-chip-row-file-tile-background #ededed File tile background.
--attachment-chip-row-file-tile-border 1px solid #e1e1e1 File tile border.
--attachment-chip-row-file-glyph-size 1.5rem Built-in document glyph size.
--attachment-chip-row-file-glyph-color #858585 Built-in document glyph color.
--attachment-chip-row-file-glyph-fold-color #ffffff Built-in document glyph fold (page-corner) color.
--attachment-chip-row-file-name-font-size 0.75rem Filename font size.
--attachment-chip-row-file-name-color #52525b Filename color.

Aligning the Row

Chips start at the leading edge. The row's track is the Scroller's, so its --scroller-justify-content token applies: set it on a class passed through classes to push a short row to the end of its container, without a rule that reaches into .scroll-container.

<AttachmentChipRow {images} classes="composer-chips" />

<style>
  :global(.composer-chips) {
    --scroller-justify-content: safe flex-end;
  }
</style>

Write safe flex-end rather than flex-end: a row with more chips than fit would otherwise lose its first chips, which end up before the start edge where the row cannot scroll to them. Unset, nothing changes.

Web Component

Tag: <sui-attachment-chip-row>

<sui-attachment-chip-row test-id="composer-attachments"></sui-attachment-chip-row>

images, files, videos, the tooltip functions, both icon snippets and every on* handler are set as JavaScript properties — none of them is serialisable as an attribute. test-id and classes are attributes.

On <sui-attachment-chip-row>, set the token on the element itself (style="--scroller-justify-content: safe flex-end"): custom properties are inherited into the shadow root, but a class in the page's stylesheet cannot match the Scroller inside it.

Web Component Events

None of the six on* props collides with a native HTMLElement handler, so each is available as a JS property AND dispatches a same-named DOM custom event (bubbles, composed) for a consumer who only calls addEventListener: onremoveimage → removeimage, onremovefile → removefile, onremovevideo → removevideo, onopenimage → openimage, onopenvideo → openvideo, onopenfile → openfile. Each detail is the same single argument the JS-property callback receives — an attachment id string for the three remove* events, the attachment object itself for the three open* events:

const row = document.querySelector('sui-attachment-chip-row');
row.addEventListener('removeimage', (e) => console.log(e.detail)); // image id
row.addEventListener('openimage', (e) => console.log(e.detail)); // image object

Slots

sui-attachment-chip-row exposes no named slot. removeIcon and fileIcon are argument-less snippets, but the component renders them once per attachment, and a named slot can be filled only once: the browser assigns light-DOM children to the first matching slot in the shadow tree, so with three chips the slotted glyph would land on the first and the other two would render empty — losing the built-in cross and document glyphs as well. Set them as properties instead, which applies to every chip:

document.querySelector('sui-attachment-chip-row').removeIcon = mySnippet;

Omitting them renders the built-in cross on each remove button and the built-in document glyph on each file tile.

ariaLabel names the attachment strip and defaults to Pending attachments. Use distinct names when a page has multiple strips. <sui-attachment-chip-row> accepts aria-label or the attachmentChipRowAriaLabel JavaScript property.