Attachment
Displays a file or image attachment with media, metadata, upload state, and actions.
Installation
Command to install the Attachment component.
Component Guide
Use the following to build the Attachment component.
from components.ui.attachment import attachmentSource Code & Dependencies
For manual installation, copy each of the source codes below in their respective locations.
components/core/core.py
components/ui/button.py
components/ui/attachment.py
Features
- Icon and image media through
attachment.media - Upload states:
idle,uploading,processing,error, anddonewith built-in styling and a shimmer while in progress - Three sizes and horizontal or vertical orientation
- A full-card
attachment.triggerthat opens a link or dialog while the actions stay independently clickable - Scrollable, snapping
attachment.groupwith an edge fade - Customizable styling through the
class_nameprop 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.
Props used: variant on attachment.media; orientation on attachment.root.
States
Set state to reflect the upload lifecycle. uploading and processing shimmer the title, and error switches to a destructive treatment.
Props used: state on attachment.root.
Sizes
Use size to switch between default, sm, and xs.
Props used: size on attachment.root.
Group
Wrap attachments in attachment.group to lay them out in a horizontally scrollable, snapping row with an edge fade.
Props used: none required beyond default attachment.group composition.
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.
Props used: link, href, aria_label on attachment.trigger.
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.
attachment.action(
hi("Cancel01Icon"), aria_label="Remove market-research.pdf"
)
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)
attachment.trigger(
link=True,
href=url,
target="_blank",
rel="noreferrer",
aria_label="Open workspace.png",
)
Button trigger (interactive action)
attachment.trigger(
on_click=handle_open,
aria_label="Open attachment preview",
)
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.