Skip to content

Attachment

File and image attachments with upload progress, errors and actions. Adapted from HextaUI (MIT).

File and image

release-notes.md4.2 KB
tasks-by-week.svg12 KB

Sizes

project-brief.pdfDefault
invoice-0142.pdfSmall
tasks.csv

States

project-brief.pdfReady to upload
release-notes.mdUploading 64%
x
tasks.csvReading 48 rows
invoice-0142.pdfLarger than 10 MB

Vertical

plan.pdf2 pages
tasks.csv48 rows

With a trigger

project-brief.pdf3 pages

Not opened yet

Group

Installation

npx shadcn@latest add @khaeli/attachment

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0
  • @keyline-icons/react ^2.2.0
  • class-variance-authority ^0.7.1

Keyboard

Tab
Moves to the attachment's trigger when it has one, then to each of its actions. A group's strip takes focus before its attachments.
EnterSpace
Activates the focused trigger or action. Actions sit above the trigger, so pressing one does not open the attachment.
Arrow LeftArrow Right
Scroll a group's strip when it has focus.

Accessible name

  • AttachmentTitle is the attachment's name. It also names the upload progress bar that state="uploading" with progress draws.
  • AttachmentAction is an icon-only button: give it an aria-label that says what it does to which file, such as Remove release-notes.md.
  • AttachmentTrigger covers the whole attachment and has no text of its own: give it an aria-label, such as Open project-brief.pdf.
  • The icon or thumbnail in AttachmentMedia is decorative beside the title: aria-hidden on an icon, an empty alt on an image.
  • A state is shown by a dashed or red border and a moving title. Say it in AttachmentDescription too, such as Uploading 64% or the reason an upload failed.
  • In a vertical attachment the actions are hidden until the pointer is over it or focus is inside it.
  • An action is drawn 20px square and takes presses over 24px with a mouse or trackpad. Two actions in a row sit 4px apart, so their press areas do not overlap.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/attachment.json