The File Bubble component renders file attachments within chat messages while maintaining visual consistency with the design system and ensuring full accessibility:Documentation Index
Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
- Message Object Processing: Extracts attachments and metadata from CometChat.MediaMessage objects
- Single File Display: File icon, name, size, and download action
- File Type Icons: Automatic icon mapping based on file extension or MIME type
- File Size Formatting: Human-readable size display (B, KB, MB, GB)
- Caption Support: Renders captions using TextMessageBubbleComponent
- Download Actions: Direct download links for all files
- Dual Styling: Supports sender (outgoing) and receiver (incoming) visual variants
- Accessibility: Full keyboard navigation and screen reader support
Live Preview — Default file bubble preview.
Open in Storybook ↗
Basic Usage
Simple File Message
Incoming vs Outgoing Messages
Properties
| Property | Type | Default | Description |
|---|---|---|---|
message | CometChat.MediaMessage | required | The CometChat.MediaMessage object to render. Contains file attachments, metadata, and sender information |
alignment | MessageBubbleAlignment | MessageBubbleAlignment.LEFT | The alignment of the message bubble. LEFT for incoming/receiver messages, RIGHT for outgoing/sender messages |
Advanced Usage
Single File Message
The component displays single file messages with file icon, name, size, and download button:- File type icon based on extension
- File name display
- File size in human-readable format
- Download button
Files with Captions
The component automatically renders captions using the TextMessageBubbleComponent:- Displays below the file(s)
- Supports rich text formatting (bold, italic, etc.)
- Supports @mentions with click events
- Supports URLs with click events
- Supports read more/less for long captions
- Inherits alignment from parent bubble
File Type Icons
The component automatically selects appropriate icons based on file type:- Documents: PDF, DOC, DOCX, TXT
- Spreadsheets: XLS, XLSX, CSV
- Presentations: PPT, PPTX
- Code Files: JS, TS, HTML, CSS, JSON
- Archives: ZIP, RAR, TAR, GZ
- Media: JPG, PNG, MP3, MP4, MOV
- Unknown: Generic file icon for unsupported types
File Size Formatting
The component automatically formats file sizes in human-readable units:- Less than 1024 bytes: Displays in bytes (B)
- Less than 1 MB: Displays in kilobytes (KB)
- Less than 1 GB: Displays in megabytes (MB)
- 1 GB or more: Displays in gigabytes (GB)
- Always rounds to 2 decimal places
- Handles missing size gracefully
Customization
Styling with CSS Variables
The File Bubble component uses CSS variables exclusively for easy customization:Available CSS Variables
| Variable | Purpose | Default |
|---|---|---|
--cometchat-spacing-1 to --cometchat-spacing-4 | Padding, margin, gap | 4px to 16px |
--cometchat-font-body-medium | File name font | 500 14px Roboto |
--cometchat-font-caption1-regular | File size font | 400 12px Roboto |
--cometchat-font-caption1-bold | Expand indicator font | 600 12px Roboto |
--cometchat-background-color-01 | Incoming bubble background | #FFFFFF |
--cometchat-background-color-02 | Incoming file item background | #F5F5F5 |
--cometchat-text-color-primary | File name color | #141414 |
--cometchat-text-color-secondary | File size color | #666666 |
--cometchat-primary-button-background | Outgoing bubble background | #6852D6 |
--cometchat-primary-button-text | Outgoing text color | #FFFFFF |
--cometchat-primary-color | Expand indicator background | #6852D6 |
--cometchat-radius-2 | Border radius | 8px |
--cometchat-radius-max | Expand indicator radius | 1000px (circular) |
--cometchat-border-color-light | Border color | #E0E0E0 |
Custom Color Schemes
Custom Expand Indicator Styling
Custom File Item Styling
Accessibility
The File Bubble component is fully accessible and follows WCAG 2.1 Level AA guidelines.WCAG 2.1 Compliance
The component meets the following WCAG 2.1 Level AA success criteria:- ✅ 1.1.1 Non-text Content (Level A): All file icons have descriptive text alternatives
- ✅ 1.3.1 Info and Relationships (Level A): Proper semantic structure with buttons and links
- ✅ 2.1.1 Keyboard (Level A): All functionality available via keyboard
- ✅ 2.4.7 Focus Visible (Level AA): Clear focus indicators on all interactive elements
- ✅ 4.1.2 Name, Role, Value (Level A): All elements have accessible names and roles
Keyboard Support
| Key | Action | Context |
|---|---|---|
Tab | Navigate to download links | When files are displayed |
ARIA Attributes
The component automatically applies appropriate ARIA attributes:| Attribute | Element | Value | Purpose |
|---|---|---|---|
aria-label | Download links | "Download [filename]" | Describes download action for each file |
Screen Reader Behavior
Screen readers announce the file bubble with:- Single file: “File, [filename], [size], Download button”
- Download links: “Link, Download [filename]“
Accessibility Best Practices
All interactive elements (expand indicator, collapse button, download links) are keyboard accessible and have visible focus indicators.
Best Practices
Use the
alignment property to distinguish between incoming and outgoing messages for proper visual styling.The component handles missing or invalid data gracefully, displaying “Size unknown” for missing file sizes and generic icons for unknown file types.
Related Components
- CometChatTextBubble: Used for rendering captions in file messages
- CometChatImageBubble: Displays image messages with grid layouts and gallery
- CometChatVideoBubble: Displays video messages with thumbnails and player
- CometChatMessageBubble: Uses File Bubble as the content view for file messages
- CometChatMessageList: Displays lists of messages including file bubbles
Technical Details
- Standalone Component: Can be imported and used independently
- Change Detection: Uses OnPush change detection strategy for optimal performance
- Dependencies:
- Angular CommonModule
- CometChat SDK for message types
- TranslatePipe for localization
- CometChatTextBubbleComponent for captions
- Bundle Size: Minimal footprint (~8KB)
- BEM CSS: Follows Block Element Modifier naming convention
- Accessibility: WCAG 2.1 Level AA compliant
Performance Considerations
Optimization Strategies
Change Detection:- Uses OnPush strategy to minimize unnecessary re-renders
- Only updates when inputs change or events are emitted
- Minimal internal state (only UI state for expand/collapse)
- All data derived from message input
- No SDK calls or service dependencies
- Attachments extracted once during message processing
- File type and size formatting cached
- Avoids repeated calculations during rendering
- Uses CSS transitions for smooth animations
- Efficient height animation without JavaScript
- Focus management optimized with setTimeout
Best Practices for Performance
The component does not make any SDK calls or service calls. All data is derived from the input message object.
For troubleshooting tips, see the Troubleshooting Guide.