Attachment

Displays a file or image attachment with media, metadata, upload state, and actions.

buridan add attachment

Component Guide

Use the following to build the Attachment component.

from components.ui.attachment import attachment

Source 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, 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.

Props used: variant on attachment.media; orientation on attachment.root.

Workspace
workspace.pngPNG · 820 KB
Desk
desk-reference.jpgJPG · 1.1 MB
Office
office-reference.jpgJPG · 940 KB

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.

selected-file.pdfReady to upload
design-system.zipUploading · 64%
market-research.pdfProcessing document
financial-model.xlsxUpload failed. Try again.
uploaded-report.pdfUploaded · 1.8 MB

Sizes

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

Props used: size on attachment.root.

Default attachmentPDF · 2.4 MB
Small attachmentPDF · 2.4 MB
Extra small attachment

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.

briefing-notes.pdfPDF · 1.4 MB
workspace.png
workspace.pngPNG · 820 KB
customers.csvCSV · 18 KB
renderer.tsxTSX · 12 KB

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.

research-summary.pdfOpen preview dialog

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.

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.

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

attachment.media

The media slot for an icon or image preview.

Prop Type Default Description
variant Literal["icon", "image"] "icon" Whether the media holds an icon or an <img>.
class_name str - Additional classes to apply to the media slot.

attachment.content

Wraps the title and description.

Prop Type Default Description
class_name str - Additional classes to apply to the content slot.

attachment.title

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

Prop Type Default Description
class_name str - Additional classes to apply to the title.

attachment.description

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

Prop Type Default Description
class_name str - Additional classes to apply to the description.

attachment.actions

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

Prop Type Default Description
class_name str - Additional classes to apply to the actions.

attachment.action

An action button. Renders a Button and accepts all of its props.

Prop Type Default Description
size Literal["default", "xs", "sm", "lg", "icon", "icon-xs", "icon-sm", "icon-lg"] "icon-xs" The button size.
class_name str - Additional classes to apply to the actions.

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.

Prop Type Default Description
link bool False If set, renders an anchor (rx.el.a) instead of a button.
aria_label str | None None Accessibility label for screen readers. Required when no visible text exists.
class_name str "" Additional CSS classes applied to the trigger.

attachment.group

Lays out attachments in a horizontally scrollable, snapping row.

Prop Type Default Description
class_name str - Additional classes to apply to the group.