Skip to main content

Attachment

A file attached to a chat message, as a chip with its preview, name, size, and a remove button. Use it in Prompt Input for a draft, and under a sent message.

Desktop viewport
Tablet viewport
Mobile viewport

When to use

  • Show the files attached to a chat message, with a remove button while the message is a draft.
  • Leave out Attachment.Remove where a file cannot be removed, such as in a sent message.
  • Use Prompt Input to take the files.

A file the app still reads

Set busy on Attachment.Root while your app reads a file, and show a Skeleton in place of Attachment.Preview. The chip sets aria-busy.

Set data-slot="attachment-preview" on the skeleton so it occupies the preview's grid cell.

Desktop viewport
Tablet viewport
Mobile viewport

Composition

Attachment.List└── Attachment.Root    ├── Attachment.Preview    ├── Attachment.Name    ├── Attachment.Size    └── Attachment.Remove

Polymorphism

Attachment.List, Attachment.Root, and Attachment.Name take asChild. Attachment.Preview picks between an image and an icon, Attachment.Size renders its own text, and Attachment.Remove owns its icon, so those three do not.

Translation

Attachment.Name sets translate="no", because a file name is an identifier.

API Reference

Attachment.List

The list of attached files, as chips that wrap. Name it, such as aria-label="Attachments".

All props from ul, plus:

PropTypeDefaultDescription
asChild?booleanfalseRender as a different element by passing a child.
Data AttributeValueDescription
data-slot"attachment-list"On the list, joined with ancestor slots.

Attachment.Root

One attached file. The chip lays out its parts by their data-slot: the preview on the left, the name over the size, and the remove button on the right.

All props from li, plus:

PropTypeDefaultDescription
busy?booleanfalseTrue while your app reads the file. The chip sets aria-busy.
asChild?booleanfalseRender as a different element by passing a child.
Data AttributeValueDescription
data-slot"attachment"On the chip, joined with ancestor slots.

Attachment.Preview

A 32-pixel thumbnail of an image file, or a file icon when src is not set. It is decorative.

All props from img except alt, width, and height.

Data AttributeValueDescription
data-slot"attachment-preview"On the image or icon wrapper, joined with ancestor slots.

Attachment.Name

The file's name. It truncates when the chip is narrow, and never translates. Set title to show the whole name on hover.

All props from span except translate, plus:

PropTypeDefaultDescription
asChild?booleanfalseRender as a different element by passing a child.
Data AttributeValueDescription
data-slot"attachment-name"On the name, joined with ancestor slots.

Attachment.Size

The file's size, such as "1.5 KB".

All props from span except children, plus:

PropTypeDefaultDescription
bytesnumberThe file's size in bytes. Required.
Data AttributeValueDescription
data-slot"attachment-size"On the size, joined with ancestor slots.

Attachment.Remove

The button that removes a file from a draft message. Name the file in the required label, such as "Remove report.pdf".

All props from Icon Button except appearance, asChild, icon, intent, and type. label is required.

Data AttributeValueDescription
data-slot"attachment-remove icon-button"On the button, joined with ancestor slots.
data-icon-button"true"Inherited from IconButton.
data-appearance"ghost"The button's appearance.
data-intent"neutral"The button's tone.
data-size"2xs" | "xs" | "sm" | "md" | "lg" | "xl"The size prop; defaults to "sm".
data-loadingpresent when isLoadingInherited from IconButton.