CometChatImageBubble component is a sophisticated image message display component that renders image messages with advanced layout capabilities. It serves as the primary content renderer for image-based messages in the CometChat Angular UIKit, handling everything from single image display to complex multi-image grid layouts with fullscreen viewing capabilities.
Overview
The Image Bubble component renders image messages while maintaining visual consistency with the design system and ensuring full accessibility:- Message Object Processing: Extracts attachments and metadata from CometChat.MediaMessage objects
- Single Image Display: Full-size image rendering with click-to-expand
- Fullscreen Gallery: Modal viewer with keyboard controls
- Caption Support: Renders captions using TextMessageBubbleComponent
- Lazy Loading: Performance optimization for image loading
- Dual Styling: Supports sender (outgoing) and receiver (incoming) visual variants
- Accessibility: Full keyboard navigation and screen reader support
Live Preview — Default image bubble preview.
Open in Storybook ↗
Basic Usage
Simple Image Message
Incoming vs Outgoing Messages
With Event Handlers
Properties
Events
Advanced Usage
Single Image Message
The component displays single image messages in full-size layout:- Full-width display with aspect ratio preservation
- Lazy loading for performance
- Click to open fullscreen gallery viewer
- Alt text for accessibility
Images with Captions
The component automatically renders captions using the TextMessageBubbleComponent:- Displays below the image(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
Fullscreen Gallery Viewer
The component includes an integrated fullscreen gallery viewer with navigation:- Fullscreen modal overlay
- Current image displayed at full size
- Navigation controls (previous/next buttons)
- Image counter (e.g., “3 of 10”)
- Close button
- Keyboard navigation:
Right Arrow- Next imageLeft Arrow- Previous imageEscape- Close viewer
- Click backdrop to close
- Focus trap for accessibility
- Body scroll prevention while open
Customization
Styling with CSS Variables
The Image Bubble component uses CSS variables exclusively for easy customization:Available CSS Variables
In addition to the global theme tokens listed above, the Image Bubble exposes component-specific CSS custom properties prefixed with
--cometchat-image-bubble-. These are scoped to the component and can be overridden on the cometchat-image-bubble selector to fine-tune the bubble’s appearance independently of the global theme.Custom Color Schemes
Custom Grid Spacing
Custom Overflow Indicator Styling
Custom Gallery Viewer Styling
Accessibility
The Image 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 images have alt text
- ✅ 1.3.1 Info and Relationships (Level A): Proper semantic structure
- ✅ 2.1.1 Keyboard (Level A): All functionality available via keyboard
- ✅ 2.4.7 Focus Visible (Level AA): Clear focus indicators in gallery viewer
- ✅ 4.1.2 Name, Role, Value (Level A): All elements have accessible names
Keyboard Support
ARIA Attributes
The component automatically applies appropriate ARIA attributes:Screen Reader Behavior
Screen readers announce the image bubble with:- Single image: “Image, [alt text]”
- Multiple images: “Image 1 of 3, [alt text]”
- Overflow indicator: “+3 more images”
- Gallery viewer: “Dialog, Image gallery, 2 of 5”
- Navigation: “Button, Next image” / “Button, Previous image”
Accessibility Best Practices
All interactive elements (images, navigation buttons) 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 uses lazy loading for images. Images outside the viewport won’t load until they’re scrolled into view.
Related Components
- CometChatVideoBubble: Displays video messages with thumbnails and player
- CometChatTextBubble: Used for rendering captions in image messages
- CometChatMessageBubble: Uses Image Bubble as the content view for image messages
- CometChatMessageList: Displays lists of messages including image bubbles
- ImageGalleryViewer: Internal component for fullscreen image viewing
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
- ImageGalleryViewerComponent for fullscreen viewing
- Bundle Size: Minimal footprint (~12KB including gallery viewer)
- 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
- Images use native
loading="lazy"attribute - Images outside viewport don’t load until scrolled into view
- Reduces initial page load time and bandwidth usage
- Layout type calculated once during message processing
- Avoids repeated calculations during rendering
- Only rendered when open (conditional rendering)
- Body scroll prevention uses efficient CSS approach
- Focus trap implemented with minimal DOM manipulation
Best Practices for Performance
Lazy loading is automatic. Images will load as they enter the viewport during scrolling.
For troubleshooting tips, see the Troubleshooting Guide.