shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Attachment shows one file as a compact card: an icon or a thumbnail, the file name, a line such as PDF · 2.4 MB, and small buttons to remove or retry it. Set its state as an upload moves from picked to sent, and its look follows.
It draws the file and never uploads it. To pick files from disk or take a drop, pair it with File Upload.
Installation
Anatomy

Usage
import { FileTextIcon, XIcon } from "lucide-react";
import {
Attachment, AttachmentAction, AttachmentActions, AttachmentContent,
AttachmentDescription, AttachmentMedia, AttachmentTitle,
} from "@/components/ui/attachment";<Attachment>
<AttachmentMedia>
<FileTextIcon aria-hidden="true" />
</AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>sales-dashboard.pdf</AttachmentTitle>
<AttachmentDescription>PDF · 2.4 MB</AttachmentDescription>
</AttachmentContent>
<AttachmentActions>
<AttachmentAction aria-label="Remove sales-dashboard.pdf">
<XIcon aria-hidden="true" />
</AttachmentAction>
</AttachmentActions>
</Attachment>AttachmentAction is a ghost icon button, so its aria-label is its only name. Put the file name in it.
Accessibility
Attachment is plain markup, and state changes only its look, through data-state, so the words are what a screen reader gets. Name each icon button with its file, such as Remove sales-dashboard.pdf, and give an AttachmentTrigger an aria-label, since it covers the card with no text of its own. Write the state into AttachmentDescription, and give a thumbnail real alt text, or an empty one when the title already names the file. Focus on the trigger or an action draws the focus ring around the whole card.
- Tab
- Moves focus to the next action button, or to the card's trigger when it has one.
- Shift+Tab
- Moves focus to the previous action or trigger.
- Enter
- Presses the focused action, or activates the trigger: opens its dialog or follows its link.
- Space
- Presses the focused action, or a trigger that is a button.
Demos
Image
Three reference photos as tall cards, with orientation set to vertical on Attachment and variant set to image on AttachmentMedia, and the name and size under each picture. An AttachmentTrigger makes each card a link to the full image in a new tab, while its remove button stays clickable above the link. Use it for screenshots and photos, where the picture identifies the file faster than its name.
States
One chip for each state, in the order a file moves through them. Idle has a dashed border, uploading and processing make the title shimmer, error turns the icon and the description red beside a retry button, and done is the plain finished chip. The icons, the spinner and the words in each description are the demo's, set to match.
Upload
Attach files opens the file picker, and each file you pick becomes a chip whose state goes from uploading to done while its description counts up to its size. An image shows its thumbnail at once from URL.createObjectURL, and removing the chip revokes that URL. A timer stands in for the request, so feed the percentage from your upload's progress events.
Sizes
The same PDF chip at size default, sm and xs. Default suits a composer, sm sits beside message text, and the demo's xs chip has no description, so it shows the name alone. Pick the smallest size that keeps the file name readable.
Group
A PDF, a photo, a CSV and a source file on one row inside AttachmentGroup, each the same fixed width with its own remove button. The row scrolls sideways, snaps to each card and fades at its edges. Use it under a composer when several files should stay on one line instead of pushing the message field down.
Trigger
An AttachmentTrigger covers the research-summary.pdf card and opens a Dialog titled with the file name. Copy link and remove sit in AttachmentActions, which stacks above the trigger, so they still take their own clicks. Use a trigger when the whole card should open a preview, and name it with an aria-label such as Preview research-summary.pdf.
FAQ
Does the Attachment component upload files?
No. It draws a file and the state you give it, and the request is yours: send the file with fetch, a form or your storage provider's SDK, and update state as it moves along. To pick files from disk or take a drop, use File Upload and render an Attachment for each file it hands you.
The Upload demo shows the loop with a plain file picker and a timer in place of the request. With the AI SDK, a file sent with a message comes back as a file part with a url, a mediaType and an optional filename, which is what an Attachment in the thread needs.
How do I show upload progress on an Attachment?
Set state to uploading while the bytes go up and to processing while the server works on the file, and the title shimmers in both. Attachment has no progress bar or percentage of its own, so put the number in AttachmentDescription, as Uploading · 64% in the States demo, and a Spinner in AttachmentMedia.
Switch to done when the request succeeds and to error when it fails, which turns the media and the description red. idle, with its dashed border, marks a file that is picked but not sent yet.
How do I show an image preview in an Attachment?
Set variant to image on AttachmentMedia and put an img inside it, as the Image demo does. The image fills a square and is cropped to cover it, so photos and screenshots of any shape line up.
Before the upload finishes, show the local file with a URL from URL.createObjectURL, which works as soon as someone picks it. Call URL.revokeObjectURL when the chip is removed or the real URL arrives, or the browser keeps the file in memory. The Upload demo does both.
How do I open a preview when someone clicks an Attachment in React?
Add an AttachmentTrigger, an invisible button that covers the whole card, and give it an aria-label such as Preview report.pdf. Buttons in AttachmentActions stay clickable above it.
To open a Dialog, make it the child of a DialogTrigger that has asChild, as the Trigger demo does. To make the card a link, use asChild on AttachmentTrigger and give it the link, as in the Image demo.
How do I show many Attachments in one row?
Wrap them in AttachmentGroup. It lays the cards out in one row that scrolls sideways, snaps to each card and fades at its edges, as the Group demo shows with four files.
Give each card a width, such as the fixed width the demo uses, so the row doesn't reflow as names get longer. For one or two files, a plain column with a gap reads better than a scroller.
How do I stop long file names from stretching an Attachment?
Give the card a width, and long names truncate on their own. AttachmentTitle and AttachmentDescription cut off with an ellipsis rather than wrapping, but an Attachment sizes itself to its content, up to the width of its container, so until it has a width there is nothing to cut to.
The States demo stretches each chip to the full width of its column, and the Group demo gives every card the same fixed width. The full name still belongs in the remove button's aria-label.
How do I add a remove button to an Attachment in Ark UI?
Put an AttachmentAction inside AttachmentActions. It is a ghost button at size icon-xs, so give it an icon with aria-hidden and an aria-label that names the file, such as Remove report.pdf, or a row of five files reads as five identical Remove buttons.
Remove the file from your own list when it is pressed, and cancel its upload if one is still running. While a file is uploading, the States demo turns that button into Cancel uploading design-system.zip, with the file name in it as well.
How does a screen reader know an Attachment is uploading or failed?
From the words on the chip, because state adds no ARIA. It sets data-state and changes the look, a dashed border, a shimmering title or red text, which a screen reader doesn't convey.
Write the state into AttachmentDescription, as the States demo does with Uploading · 64%, Processing document and Upload failed. The demo's Spinner is a status element named Loading, which says something is in progress but not which file, so announce a finished or failed upload yourself in a live region with the file name.
API Reference
Attachment
<div> data-slot="attachment"
orientation?"horizontal" | "vertical"
Lays its preview and details out in a row (horizontal) or a column
(vertical).
- Type
"horizontal" | "vertical"- Default
"horizontal"
size?"default" | "sm" | "xs"
The size.
- Type
"default" | "sm" | "xs"- Default
"default"
state?"idle" | "uploading" | "processing" | "error" | "done"
Its upload state, which sets its look: idle, uploading, processing, error or done.
- Type
"idle" | "uploading" | "processing" | "error" | "done"- Default
"done"
className?string
Merged with the part's classes.
data-orientation?string
Mirrors orientation.
data-size?string
Mirrors size.
data-state?string
Mirrors state.
AttachmentAction
data-slot="attachment-action"
clickEffect?boolean
Apply a click effect to the button.
- Default
true
isLoading?boolean
Show a loading indicator.
- Default
false
pill?boolean
Fully rounded corners.
- Default
false
size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Ark default: md.
- Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"- Default
"icon-xs"
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Ark default: default.
- Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"- Default
"ghost"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
AttachmentActions
<div> data-slot="attachment-actions"
className?string
Merged with the part's classes.
AttachmentContent
<div> data-slot="attachment-content"
className?string
Merged with the part's classes.
AttachmentDescription
<span> data-slot="attachment-description"
className?string
Merged with the part's classes.
AttachmentGroup
<div> data-slot="attachment-group"
className?string
Merged with the part's classes.
AttachmentMedia
<div> data-slot="attachment-media"
variant?"icon" | "image"
The visual style.
- Type
"icon" | "image"- Default
"icon"
className?string
Merged with the part's classes.
data-variant?string
Mirrors variant.
AttachmentTitle
<span> data-slot="attachment-title"
className?string
Merged with the part's classes.
AttachmentTrigger
<button> data-slot="attachment-trigger"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
- Default
false
className?string
Merged with the part's classes.












