Attachment
Displays a file or image attachment with media, metadata, upload state, and actions.
Installation
Copy the following code into your app directory.
Command
Command
Manual
Manual
uv
Anatomy
Use the following composition to build an Attachment component.
Features
Icon and image media through attachment.media
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 attachment.trigger that opens a link or dialog while the actions stay independently clickable
Scrollable, snapping attachment.group with an edge fade
Customizable styling through the class_name prop on every part
Examples
Image
Set variant="image" on attachment.media and render an rx.el.img() inside it. Use orientation="vertical" to stack the media above the content.
States
Set state to reflect the upload lifecycle. uploading and processing shimmer the title, and error switches to a destructive treatment.
Sizes
Use size to switch between default, sm, and xs.
Group
Wrap attachments in attachment.group to lay them out in a horizontally scrollable, snapping row with an edge fade.
Trigger
Add an attachment.trigger to make the whole card open a link or dialog. It fills the card behind the actions, so the actions stay clickable.
Accessibility
attachment.action renders a Button, and attachment.trigger renders either a real rx.el.button() or a rx.el.a() if the link prop is set to True. Follow the guidance below so both are operable and announced.
Label icon-only actions
attachment.action is usually icon-only, so give each one an aria-label describing the action and its target.
python
Label the trigger
attachment.trigger overlays the entire attachment with a clickable surface.
Use aria_label to describe what activating the attachment does. This is required when the trigger has no visible text.
Link trigger (opens a URL)
python
Button trigger (interactive action)
python
The trigger sits behind the actions in the stacking order, so an attachment.action and the attachment.trigger never trap each other — both remain separately focusable and clickable.
Keyboard scrolling
An attachment.group 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 attachment.description so the state is not conveyed by color alone.
API Reference
attachment.root
The root attachment container.
attachment.media
The media slot for an icon or image preview.
attachment.content
Wraps the title and description.
attachment.title
The attachment name. Shimmers while the attachment is uploading or processing.
attachment.description
Secondary metadata such as the file type, size, or upload status.
attachment.actions
A container for one or more actions, aligned to the end of the attachment.
attachment.action
An action button. Renders a Button and accepts all of its props.
attachment.trigger
A full-card overlay that activates the attachment. Renders a rx.el.button by default or a rx.el.a when link=True.
attachment.group
Lays out attachments in a horizontally scrollable, snapping row.