0.04K

Displays a file or image attachment with media, metadata, upload state, and 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
import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentGroup,
  AttachmentMedia,
  AttachmentTitle,
} from '@/components/ui/attachment';
import { Spinner } from '@/components/ui/spinner';

import FileCodeIcon from '~icons/lucide/file-code';
import XIcon from '~icons/lucide/x';

const images = [
  {
    name: 'workspace.png',
    meta: 'PNG · 820 KB',
    src: 'https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80',
    alt: 'Workspace',
  },
  {
    name: 'desk-reference.jpg',
    meta: 'JPG · 1.1 MB',
    src: 'https://images.unsplash.com/photo-1497215728101-856f4ea42174?w=900&auto=format&fit=crop&q=80',
    alt: 'Desk',
  },
  {
    name: 'office-reference.jpg',
    meta: 'JPG · 940 KB',
    src: 'https://images.unsplash.com/photo-1497366811353-6870744d04b2?w=900&auto=format&fit=crop&q=80',
    alt: 'Office',
  },
];

<template>
  {{! template-lint-disable no-potential-path-strings }}
  <div class="mx-auto flex w-full max-w-sm flex-col gap-3 py-12">
    <AttachmentGroup>
      {{#each images as |image|}}
        <Attachment @orientation="vertical">
          <AttachmentMedia @variant="image">
            <img alt={{image.alt}} src={{image.src}} />
          </AttachmentMedia>
          <AttachmentContent>
            <AttachmentTitle>{{image.name}}</AttachmentTitle>
            <AttachmentDescription>{{image.meta}}</AttachmentDescription>
          </AttachmentContent>
        </Attachment>
      {{/each}}
    </AttachmentGroup>
    <Attachment @class="w-full" @state="uploading">
      <AttachmentMedia>
        <Spinner />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>sales-dashboard.pdf</AttachmentTitle>
        <AttachmentDescription>Uploading · 64%</AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Cancel upload">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
    <Attachment @class="w-full">
      <AttachmentMedia>
        <FileCodeIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>message-renderer.tsx</AttachmentTitle>
        <AttachmentDescription>TypeScript · 12 KB</AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Remove message-renderer.tsx">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
  </div>
</template>

The Attachment component displays a file or image attachment, its media, name, and metadata, with optional actions and upload state. Use it for files and images in chat composers, message threads, and upload lists.

Installation

pnpm dlx shadcn-ember@latest add attachment

Usage

import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
} from '@/components/ui/attachment';
<Attachment>
  <AttachmentMedia>
    <FileTextIcon />
  </AttachmentMedia>
  <AttachmentContent>
    <AttachmentTitle>sales-dashboard.pdf</AttachmentTitle>
    <AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
  </AttachmentContent>
  <AttachmentActions>
    <AttachmentAction aria-label="Remove sales-dashboard.pdf">
      <XIcon />
    </AttachmentAction>
  </AttachmentActions>
</Attachment>

Composition

Use the following composition to build an attachment:

Attachment
├── AttachmentMedia
├── AttachmentContent
│   ├── AttachmentTitle
│   └── AttachmentDescription
├── AttachmentActions
│   └── AttachmentAction
└── AttachmentTrigger

Use AttachmentGroup to lay out multiple attachments in a scrollable row:

AttachmentGroup
├── Attachment
└── Attachment

Features

  • Icon and image media through AttachmentMedia
  • Upload states: idle , uploading , processing , error , and done with built-in styling and a shimmer while in progress
  • Three sizes and horizontal or vertical orientation
  • A full-card AttachmentTrigger that opens a link or dialog while the actions stay independently clickable
  • Scrollable, snapping AttachmentGroup with an edge fade
  • Customizable styling through the @class argument on every part

Examples

Image

Set @variant="image" on AttachmentMedia and render an <img> inside it. Use @orientation="vertical" to stack the media above the content.

Workspace
workspace.png PNG · 820 KB
Desk
desk-reference.jpg JPG · 1.1 MB
Office
office-reference.jpg JPG · 940 KB
import { concat } from '@ember/helper';

import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentGroup,
  AttachmentMedia,
  AttachmentTitle,
  AttachmentTrigger,
} from '@/components/ui/attachment';

import XIcon from '~icons/lucide/x';

const images = [
  {
    name: 'workspace.png',
    meta: 'PNG · 820 KB',
    src: 'https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80',
    alt: 'Workspace',
  },
  {
    name: 'desk-reference.jpg',
    meta: 'JPG · 1.1 MB',
    src: 'https://images.unsplash.com/photo-1497215728101-856f4ea42174?w=900&auto=format&fit=crop&q=80',
    alt: 'Desk',
  },
  {
    name: 'office-reference.jpg',
    meta: 'JPG · 940 KB',
    src: 'https://images.unsplash.com/photo-1497366811353-6870744d04b2?w=900&auto=format&fit=crop&q=80',
    alt: 'Office',
  },
];

<template>
  {{! template-lint-disable no-potential-path-strings }}
  <div class="mx-auto w-full max-w-sm py-12">
    <AttachmentGroup @class="w-full">
      {{#each images as |image|}}
        <Attachment @orientation="vertical">
          <AttachmentMedia @variant="image">
            <img alt={{image.alt}} src={{image.src}} />
          </AttachmentMedia>
          <AttachmentContent>
            <AttachmentTitle>{{image.name}}</AttachmentTitle>
            <AttachmentDescription>{{image.meta}}</AttachmentDescription>
          </AttachmentContent>
          <AttachmentActions>
            <AttachmentAction aria-label="Remove {{image.name}}">
              <XIcon />
            </AttachmentAction>
          </AttachmentActions>
          <AttachmentTrigger @asChild={{true}} as |trigger|>
            <a
              aria-label={{concat "Open " image.name}}
              class={{trigger.classes}}
              data-slot="attachment-trigger"
              href={{image.src}}
              rel="noopener noreferrer"
              target="_blank"
            ></a>
          </AttachmentTrigger>
        </Attachment>
      {{/each}}
    </AttachmentGroup>
  </div>
</template>

States

Set @state to reflect the upload lifecycle. uploading and processing shimmer the title, and error switches to a destructive treatment.

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
import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
} from '@/components/ui/attachment';
import { Spinner } from '@/components/ui/spinner';

import CheckIcon from '~icons/lucide/check';
import ClockIcon from '~icons/lucide/clock';
import FileTextIcon from '~icons/lucide/file-text';
import FileWarningIcon from '~icons/lucide/file-warning';
import RefreshCwIcon from '~icons/lucide/refresh-cw';
import XIcon from '~icons/lucide/x';

<template>
  <div class="mx-auto flex w-full max-w-sm flex-col gap-2 py-12">
    <Attachment @class="w-full" @state="idle">
      <AttachmentMedia>
        <ClockIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>selected-file.pdf</AttachmentTitle>
        <AttachmentDescription>Ready to upload</AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Remove selected-file.pdf">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
    <Attachment @class="w-full" @state="uploading">
      <AttachmentMedia>
        <Spinner />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>design-system.zip</AttachmentTitle>
        <AttachmentDescription>Uploading · 64%</AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Cancel upload">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
    <Attachment @class="w-full" @state="processing">
      <AttachmentMedia>
        <FileTextIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>market-research.pdf</AttachmentTitle>
        <AttachmentDescription>Processing document</AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Remove market-research.pdf">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
    <Attachment @class="w-full" @state="error">
      <AttachmentMedia>
        <FileWarningIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>financial-model.xlsx</AttachmentTitle>
        <AttachmentDescription>
          Upload failed. Try again.
        </AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Retry upload">
          <RefreshCwIcon />
        </AttachmentAction>
        <AttachmentAction aria-label="Remove financial-model.xlsx">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
    <Attachment @class="w-full" @state="done">
      <AttachmentMedia>
        <CheckIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>uploaded-report.pdf</AttachmentTitle>
        <AttachmentDescription>Uploaded · 1.8 MB</AttachmentDescription>
      </AttachmentContent>
      <AttachmentActions>
        <AttachmentAction aria-label="Remove uploaded-report.pdf">
          <XIcon />
        </AttachmentAction>
      </AttachmentActions>
    </Attachment>
  </div>
</template>

Sizes

Use @size to switch between default , sm , and xs .

Default attachment PDF · 2.4 MB
Small attachment PDF · 2.4 MB
Extra small attachment
import {
  Attachment,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
} from '@/components/ui/attachment';

import FileTextIcon from '~icons/lucide/file-text';

<template>
  <div class="mx-auto flex w-full max-w-sm flex-col gap-3 py-12">
    <Attachment @class="w-full" @size="default">
      <AttachmentMedia>
        <FileTextIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>Default attachment</AttachmentTitle>
        <AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
      </AttachmentContent>
    </Attachment>
    <Attachment @class="w-full" @size="sm">
      <AttachmentMedia>
        <FileTextIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>Small attachment</AttachmentTitle>
        <AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
      </AttachmentContent>
    </Attachment>
    <Attachment @class="w-full" @size="xs">
      <AttachmentMedia>
        <FileTextIcon />
      </AttachmentMedia>
      <AttachmentContent>
        <AttachmentTitle>Extra small attachment</AttachmentTitle>
      </AttachmentContent>
    </Attachment>
  </div>
</template>

Group

Wrap attachments in AttachmentGroup to lay them out in a horizontally scrollable, snapping row with an edge fade.

briefing-notes.pdf PDF · 1.4 MB
workspace.png
workspace.png PNG · 820 KB
customers.csv CSV · 18 KB
renderer.tsx TSX · 12 KB
import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentGroup,
  AttachmentMedia,
  AttachmentTitle,
} from '@/components/ui/attachment';

import type { ComponentLike } from '@glint/template';

import FileCodeIcon from '~icons/lucide/file-code';
import FileTextIcon from '~icons/lucide/file-text';
import TableIcon from '~icons/lucide/table';
import XIcon from '~icons/lucide/x';

const items = [
  {
    name: 'briefing-notes.pdf',
    meta: 'PDF · 1.4 MB',
    icon: FileTextIcon as ComponentLike,
  },
  {
    name: 'workspace.png',
    meta: 'PNG · 820 KB',
    src: 'https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80',
  },
  {
    name: 'customers.csv',
    meta: 'CSV · 18 KB',
    icon: TableIcon as ComponentLike,
  },
  {
    name: 'renderer.tsx',
    meta: 'TSX · 12 KB',
    icon: FileCodeIcon as ComponentLike,
  },
];

<template>
  {{! template-lint-disable no-potential-path-strings }}
  <div class="mx-auto w-full max-w-sm py-12">
    <AttachmentGroup @class="w-full">
      {{#each items as |item|}}
        <Attachment @class="w-64">
          {{#if item.src}}
            <AttachmentMedia @variant="image">
              <img alt={{item.name}} src={{item.src}} />
            </AttachmentMedia>
          {{else if item.icon}}
            <AttachmentMedia>
              <item.icon />
            </AttachmentMedia>
          {{/if}}
          <AttachmentContent>
            <AttachmentTitle>{{item.name}}</AttachmentTitle>
            <AttachmentDescription>{{item.meta}}</AttachmentDescription>
          </AttachmentContent>
          <AttachmentActions>
            <AttachmentAction aria-label="Remove {{item.name}}">
              <XIcon />
            </AttachmentAction>
          </AttachmentActions>
        </Attachment>
      {{/each}}
    </AttachmentGroup>
  </div>
</template>

Trigger

Add an AttachmentTrigger to make the whole card open a link or dialog. It fills the card behind the actions, so the actions stay clickable.

research-summary.pdf Open preview dialog
import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
  AttachmentTrigger,
} from '@/components/ui/attachment';
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from '@/components/ui/dialog';

import CopyIcon from '~icons/lucide/copy';
import FileSearchIcon from '~icons/lucide/file-search';
import XIcon from '~icons/lucide/x';

<template>
  <div class="mx-auto w-full max-w-sm py-12">
    <Dialog>
      <Attachment @class="w-full">
        <AttachmentMedia>
          <FileSearchIcon />
        </AttachmentMedia>
        <AttachmentContent>
          <AttachmentTitle>research-summary.pdf</AttachmentTitle>
          <AttachmentDescription>Open preview dialog</AttachmentDescription>
        </AttachmentContent>
        <AttachmentActions>
          <AttachmentAction aria-label="Copy link">
            <CopyIcon />
          </AttachmentAction>
          <AttachmentAction aria-label="Remove research-summary.pdf">
            <XIcon />
          </AttachmentAction>
        </AttachmentActions>
        <DialogTrigger @asChild={{true}} as |trigger|>
          <AttachmentTrigger
            aria-label="Preview research-summary.pdf"
            {{trigger.modifiers}}
          />
        </DialogTrigger>
      </Attachment>
      <DialogContent @class="sm:max-w-md">
        <DialogHeader>
          <DialogTitle>research-summary.pdf</DialogTitle>
          <DialogDescription>
            The attachment trigger fills the card and opens the dialog, while
            the actions stay independently clickable above it.
          </DialogDescription>
        </DialogHeader>
      </DialogContent>
    </Dialog>
  </div>
</template>
<Dialog>
  <Attachment>
    {{! media, content, actions }}
    <DialogTrigger @asChild={{true}} as |trigger|>
      <AttachmentTrigger
        aria-label="Preview research-summary.pdf"
        {{trigger.modifiers}}
      />
    </DialogTrigger>
  </Attachment>
  <DialogContent>{{! ... }}</DialogContent>
</Dialog>

Accessibility

AttachmentAction renders a Button , and AttachmentTrigger renders a real <button> (or your element via @asChild ). Follow the guidance below so both are operable and announced.

Label icon-only actions

AttachmentAction is usually icon-only, so give each one an aria-label describing the action and its target.

<AttachmentAction aria-label="Remove sales-dashboard.pdf">
  <XIcon />
</AttachmentAction>

Label the trigger

AttachmentTrigger covers the card with no text of its own, so give it an aria-label for what activating it does.

<AttachmentTrigger @asChild={{true}} as |trigger|>
  <a
    aria-label="Open workspace.png"
    class={{trigger.classes}}
    data-slot="attachment-trigger"
    href={{this.url}}
    rel="noreferrer"
    target="_blank"
  ></a>
</AttachmentTrigger>

The trigger sits behind the actions in the stacking order, so an AttachmentAction and the AttachmentTrigger never trap each other — both remain separately focusable and clickable.

Keyboard scrolling

An AttachmentGroup scrolls horizontally. When its attachments are interactive—a trigger or actions—keyboard users reach off-screen items by tabbing to them. For a row of presentational attachments, make the group itself focusable and scrollable by adding tabindex="0" , role="group" , and an aria-label .

Meaning beyond color

The error state uses a destructive color. Keep the failure reason in AttachmentDescription so the state is not conveyed by color alone.

API Reference

Attachment

The root attachment container.

Prop Type Default Description
@state "idle" | "uploading" | "processing" | "error" | "done" "done" The upload state. Drives styling and the shimmer.
@size "default" | "sm" | "xs" "default" The attachment size.
@orientation "horizontal" | "vertical" "horizontal" Lay the media beside or above the content.
@class string - Additional classes to apply to the root element.

AttachmentMedia

The media slot for an icon or image preview.

Prop Type Default Description
@variant "icon" | "image" "icon" Whether the media holds an icon or an <img> .
@class string - Additional classes to apply to the media slot.

AttachmentContent

Wraps the title and description.

Prop Type Default Description
@class string - Additional classes to apply to the content slot.

AttachmentTitle

The attachment name. Shimmers while the attachment is uploading or processing .

Prop Type Default Description
@class string - Additional classes to apply to the title.

AttachmentDescription

Secondary metadata such as the file type, size, or upload status.

Prop Type Default Description
@class string - Additional classes to apply to the description.

AttachmentActions

A container for one or more actions, aligned to the end of the attachment.

Prop Type Default Description
@class string - Additional classes to apply to the actions.

AttachmentAction

An action button. Renders a and accepts all of its arguments.

Prop Type Default Description
@variant string "ghost" The button variant.
@size string "icon-xs" The button size.
@class string - Additional classes to apply to the button.

AttachmentTrigger

A full-card overlay that activates the attachment. Renders a <button> by default.

Prop Type Default Description
@asChild boolean false Yield { classes } to render your own element, such as a link.
@class string - Additional classes to apply to the trigger element.

AttachmentGroup

Lays out attachments in a horizontally scrollable, snapping row.

Prop Type Default Description
@class string - Additional classes to apply to the group.