Attachment previews and composer file input helpers for AI chat surfaces.
Use ChatAttachment for compact file previews in messages or prompt composers.
import {ChatAttachment, ChatAttachmentGroup, ChatAttachmentInput, PromptInput} from "@heroui-pro/react";
<ChatAttachmentGroup>
<ChatAttachment name="brief.pdf" size={824120}>
<ChatAttachment.Preview>
<ChatAttachment.Icon />
</ChatAttachment.Preview>
<ChatAttachment.Info>
<ChatAttachment.Name />
<ChatAttachment.Size />
</ChatAttachment.Info>
<ChatAttachment.Remove /> {/* Optional */}
</ChatAttachment>
</ChatAttachmentGroup>;
<ChatAttachmentInput onFilesSelected={setFiles}>
<ChatAttachmentInput.Trigger /> {/* Optional */}
<ChatAttachmentInput.Dropzone
render={(props) => <PromptInput.Shell {...props}>{/* ... */}</PromptInput.Shell>}
/>
</ChatAttachmentInput>;Pair ChatAttachmentInput with PromptInput to support file picker and drag-and-drop uploads.
When generating local image or video previews with URL.createObjectURL, revoke each blob: URL
when the attachment is removed, when the composer is cleared, and when the component unmounts.
Use ChatAttachmentGroup to arrange multiple attachments.
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The Chat Attachment component uses these CSS classes:
.chat-attachment: Attachment root (thumbnail tile or file card).chat-attachment__preview: Preview media wrapper (thumbnail or icon tile).chat-attachment__preview-image: Image preview.chat-attachment__preview-video: Video preview.chat-attachment__icon: Format-specific file-type icon.chat-attachment__info: File name and size wrapper (hover overlay for media).chat-attachment__name: File name.chat-attachment__size: Formatted file size.chat-attachment__remove: Remove button.chat-attachment-group: Attachment group wrapper[data-variant="media|file"] on .chat-attachment: "media" for image and video thumbnails, "file" for the horizontal file cardImage and video attachments render as a square thumbnail, with the file name revealed on hover. Other file types render as a horizontal card with a format-specific icon, file name, and size.
| Prop | Type | Default | Description |
|---|---|---|---|
mediaType | 'audio' | 'document' | 'image' | 'unknown' | 'video' | inferred | Attachment media type |
mimeType | string | - | MIME type used to infer media type and icon |
name | string | - | Attachment file name (also used to infer the icon by extension) |
size | number | - | File size in bytes, formatted for display |
src | string | - | Preview URL for image or video attachments |
children | ReactNode | default content | Custom attachment content |
Renders the image, video, or format-specific icon preview. Accepts children to replace the preview content.
Renders the format-specific file-type icon inferred from mimeType/name (PDF, archive, spreadsheet, document, code, audio, video, image, or generic). Accepts children to override the icon.
Wrapper for the file name and size. Defaults to ChatAttachment.Name and ChatAttachment.Size when no children are provided. In the media variant it renders as a hover overlay.
Renders the file name. Defaults to the name prop.
Renders the formatted file size from the size prop (bytes). Renders nothing when no size is available.
Extends HeroUI CloseButton props. Use it to remove an attachment from composer state.
Provides file-picker and drag-and-drop behavior.
| Prop | Type | Default | Description |
|---|---|---|---|
accept | string | - | Native file input accept filter |
multiple | boolean | true | Allow multiple files |
disabled | boolean | false | Disable picker and drop behavior |
onFilesSelected | (files: File[]) => void | - | Called when files are selected or dropped |
Opens the hidden file input. Use render to wire it to another button.
Adds drag-and-drop file handling. Use render to attach drop behavior to PromptInput.Shell.
inferChatAttachmentFileKind(mimeType?, name?): Resolves the file kind used to pick the icon.formatChatAttachmentSize(bytes?): Formats a byte count as B/KB/MB/GB.Resources