Attachment

Display files, image previews, upload states, and file actions.

  • Workspace

    workspace.png

    PNG · 820 KB

  • Desk

    desk-reference.jpg

    JPG · 1.1 MB

  • Office

    office-reference.jpg

    JPG · 940 KB

sales-dashboard.pdf

Uploading · 64%

message-renderer.tsx

TypeScript · 12 KB

Usage

With a Basecoat style bundle loaded, use a <div class="attachment"> with an optional <figure> for media, <section> for the filename and description, and <div> for action buttons. No Attachment JavaScript is required.

<div class="attachment">
  <figure aria-hidden="true">
    <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" ><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" /><path d="M14 2v5a1 1 0 0 0 1 1h5" /><path d="M10 9H8" /><path d="M16 13H8" /><path d="M16 17H8" /></svg>
  </figure>
  <section>
    <p dir="auto">report.pdf</p>
    <p>PDF · 2.4 MB</p>
  </section>
</div>

HTML structure

The root is not tied to an element: use <div> for a standalone attachment or <li> inside a file list. The first element in <section> is the filename; a <p> is sufficient unless the page needs a heading. Following elements contain metadata. Hide decorative icon figures with aria-hidden="true". A neutral <div> wrapper avoids adding a page-footer landmark. Image media is detected from <figure><img ...></figure>; no extra variant is needed. Actions reuse Button with data-variant="ghost" data-size="icon-xs".

An optional direct child <a> or <button> makes the entire card clickable. Give it an accessible name. Place the full-card trigger before the final <div> and keep action buttons inside that wrapper so they remain independent of the full-card trigger; do not nest buttons inside a link or another button.

Attachment presents your files and upload status. Your application supplies the actual upload, cancellation, retry, and removal behavior. The demo removal buttons remove their sample cards and move focus to the containing list or example. In your application, return focus to the next attachment or file input after removal. These examples do not manage files on a server.

Examples

Image

Use data-orientation="vertical" for thumbnails above their labels. Here the card opens the image, while its separate remove button removes the sample.

  • Workspace

    workspace.png

    PNG · 820 KB

  • Desk

    desk-reference.jpg

    JPG · 1.1 MB

  • Office

    office-reference.jpg

    JPG · 940 KB

States

Use data-state="idle", uploading, processing, error, or done. The default is done. Uploading and processing titles reuse Shimmer; it stays readable without animation in reduced-motion and forced-colors modes. Include components/shimmer.css when importing individual component styles.

The retry button resets this sample to the idle state. Connect it to your uploader in an application, and announce changing status through a live region when appropriate.

selected-file.pdf

Ready to upload

design-system.zip

Uploading · 64%

market-research.pdf

Processing document

financial-model.xlsx

Upload failed. Try again.

uploaded-report.pdf

Uploaded · 1.8 MB

Sizes

Use the default size, data-size="sm", or data-size="xs". Sizing follows the active style pack.

Default attachment

PDF · 2.4 MB

Small attachment

PDF · 2.4 MB

Extra small attachment

Group

Use <ul class="attachment-group" role="list"> with <li class="attachment"> children for a native horizontally scrolling file list with scroll snapping. Give the group a label and tabindex="0" so keyboard users can scroll it. Unlike upstream, the row omits horizontal scroll padding so arrow keys advance reliably and the last card remains fully visible. Scroll-edge fades progressively enhance browsers with scroll-driven animations; other browsers show an unfaded row. Fades are disabled while the group has keyboard focus and in forced-colors mode.

  • briefing-notes.pdf

    PDF · 1.4 MB

  • Workspace

    workspace.png

    PNG · 820 KB

  • customers.csv

    CSV · 18 KB

  • renderer.tsx

    TSX · 12 KB

Trigger

A direct child button opens a native Dialog. The copy and remove actions remain independently clickable. Copy link copies a link to this example.

research-summary.pdf

Open preview dialog

research-summary.pdf

The attachment trigger fills the card and opens the dialog, while the actions stay independently clickable above it.

RTL

Set dir="rtl" on the containing element. Media and actions follow the reading direction, including overlays on vertical thumbnails.

تقرير-البحث.pdf

PDF · 1.4 MB

  • Workspace

    workspace.png

    PNG · 820 KB

  • Desk

    desk-reference.jpg

    JPG · 1.1 MB

  • Office

    office-reference.jpg

    JPG · 940 KB