The CometChatMessageBubble component is a versatile container component that renders chat messages with configurable view slots. It serves as the primary wrapper for displaying messages in the CometChat Angular UIKit, handling message alignment, options menus, status indicators, and content rendering based on message type.
Overview
The Message Bubble component provides a flexible architecture for rendering different message types while maintaining consistent styling and behavior:
- Message Type Routing: Automatically renders appropriate bubble component based on message type (text, image, video, audio, file)
- Configurable View Slots: Override any section (leading, header, content, footer, etc.) with custom templates
- Message Options Menu: Context menu with hover/click behavior for message actions
- Group vs 1-on-1 Handling: Automatically shows/hides avatar and sender name based on conversation type
- Alignment Variants: Supports incoming (left), outgoing (right), and action (center) alignments
- Status Indicators: Displays timestamps, read receipts, and edited labels
- Reply Preview: Shows quoted message preview for replies
- Accessibility: Full keyboard navigation and screen reader support
Message Bubble Structure
The Message Bubble is composed of several configurable view slots that can be customized independently:
View Slot Descriptions
| View Slot | Description | Default Content |
|---|
| bubbleView | Complete bubble override - replaces entire message bubble | Header + Reply + Content + StatusInfo + Bottom + Footer |
| leadingView | Avatar section on the left side of incoming messages | User avatar with online status |
| headerView | Sender information above the message content | Sender name (shown in group chats) |
| replyView | Quoted message preview for reply messages | Message preview component |
| contentView | Main message content area | Text/Image/Video/Audio/File bubble |
| statusInfoView | Timestamp and delivery status | Time, receipts, edited label |
| bottomView | Additional content below the message | Link previews, load more button |
| footerView | Reactions and footer content | Reaction emojis |
| threadView | Thread reply indicators | Reply count and thread icon |
Basic Usage
Simple Message Bubble
Incoming vs Outgoing Messages
With Message Options
API Reference
Properties
| Property | Type | Default | Description |
|---|
message | CometChat.BaseMessage | required | The CometChat message object to render |
alignment | MessageBubbleAlignment | right | Alignment of the bubble: left (incoming), right (outgoing), center (action) |
group | CometChat.Group | null | null | Group context for group conversations. Enables avatar and sender name display |
options | Array<CometChatActionsIcon | CometChatActionsView> | [] | Message options to display in context menu |
quickOptionsCount | number | 2 | Number of options to show directly on bubble before overflow |
textFormatters | CometChatTextFormatter[] | [] | Text formatters for text message content |
dateFormat | CalendarObject | undefined | Custom date format for timestamp display |
translatedText | string | undefined | Translated text to display for text messages |
reactionsRequestBuilder | CometChat.ReactionsRequestBuilder | undefined | Custom request builder for fetching reactions |
isSelected | boolean | false | Whether the message bubble is currently selected |
ariaPosinset | number | undefined | ARIA position-in-set attribute for the message in the list |
ariaSetsize | number | undefined | ARIA set-size attribute for the total message count |
View Override Properties
| Property | Type | Default | Description |
|---|
bubbleView | TemplateRef<any> | undefined | Complete bubble override - replaces entire message bubble |
leadingView | TemplateRef<any> | undefined | Custom template for leading view (avatar section) |
headerView | TemplateRef<any> | undefined | Custom template for header view (sender name section) |
replyView | TemplateRef<any> | undefined | Custom template for reply view (quoted message preview) |
contentView | TemplateRef<any> | undefined | Custom template for content view (main message content) |
bottomView | TemplateRef<any> | undefined | Custom template for bottom view |
footerView | TemplateRef<any> | undefined | Custom template for footer view (reactions) |
statusInfoView | TemplateRef<any> | undefined | Custom template for status info view (timestamp, receipts) |
threadView | TemplateRef<any> | undefined | Custom template for thread view |
Display Control Properties
| Property | Type | Default | Description |
|---|
hideAvatar | boolean | false | Whether to hide the avatar |
hideSenderName | boolean | false | Whether to hide the sender name |
hideReceipts | boolean | false | Whether to hide read receipts |
hideTimestamp | boolean | false | Whether to hide the timestamp |
showError | boolean | false | Whether to show error state indicator |
hideModerationView | boolean | false | Whether to hide moderation status indicators |
disableInteraction | boolean | false | When true, disables all interactive elements within the bubble (context menu, reactions, etc.) |
Events
| Event | Payload Type | Description |
|---|
optionClick | ContextMenuItem | Emitted when a message option is clicked |
avatarClick | CometChat.User | Emitted when the avatar is clicked |
replyPreviewClick | CometChat.BaseMessage | Emitted when the reply preview is clicked |
threadRepliesClick | CometChat.BaseMessage | Emitted when the thread replies view is clicked |
reactionClick | { reaction: CometChat.ReactionCount, message: CometChat.BaseMessage } | Emitted when a reaction is clicked |
reactionListItemClick | { reaction: CometChat.Reaction, message: CometChat.BaseMessage } | Emitted when a reaction list item (user) is clicked |
mediaToggle | CometChat.BaseMessage | Emitted when Space key toggles media playback on audio/video bubbles |
messageActionsOpen | CometChat.BaseMessage | Emitted when message actions are triggered via keyboard |
Bubble Parts Customization
Each bubble part can be customized independently using Angular TemplateRef. The customization follows a priority system:
- Input template ref (passed directly to component) - Highest priority
- Service configured view (via
MessageBubbleConfigService) - Medium priority
- Default rendering - Lowest priority
bubbleView
The bubbleView provides complete control over the entire message bubble. When set, it replaces all other views (header, content, footer, etc.).
Use Case: When you need a completely custom message layout that doesn’t follow the standard structure.
leadingView
The leadingView customizes the avatar section that appears on the left side of incoming messages in group conversations.
Use Case: Custom avatar styling, adding status badges, or showing additional user information.
The headerView customizes the sender name section that appears above the message content in group conversations.
Use Case: Adding user roles, custom badges, or additional sender information.
replyView
The replyView customizes the quoted message preview that appears when a message is a reply to another message.
Use Case: Custom reply preview styling, showing additional context, or different preview formats.
contentView
The contentView customizes the main message content area. This is where the actual message (text, image, video, etc.) is displayed.
Use Case: Custom message rendering, adding interactive elements, or completely different content layouts.
statusInfoView
The statusInfoView customizes the timestamp and delivery status section that appears inside the message bubble.
Use Case: Custom timestamp formats, additional status indicators, or different receipt icons.
bottomView
The bottomView customizes the section below the main content, typically used for link previews, warnings, or additional information.
Use Case: Link previews, content warnings, or expandable content sections.
The footerView customizes the reactions section that appears below the message content.
Use Case: Custom reaction display, adding additional footer actions, or different reaction layouts.
threadView
The threadView customizes the thread reply indicator that appears when a message has replies.
Use Case: Custom thread indicators, showing reply previews, or different thread navigation styles.
Service-Based Customization
For global customization across all message bubbles, use the MessageBubbleConfigService. This allows you to set custom views that apply to all instances without passing templates to each component.
Using MessageBubbleConfigService
MessageBubbleConfigService API
| Method | Parameters | Description |
|---|
setBubbleView | messageType: string, map: BubblePartMap | Set custom views for a specific message type |
setGlobalStatusInfoView | view: TemplateRef<any> | Set status info view for all message types |
setGlobalLeadingView | view: TemplateRef<any> | Set leading view for all message types |
setGlobalHeaderView | view: TemplateRef<any> | Set header view for all message types |
setMessageTemplates | maps: Record<string, BubblePartMap> | Set multiple message type customizations |
getView | messageType: string, part: BubblePart | Get the configured view for a message type and part |
clearAll | none | Clear all configured views |
Scoping for Multiple Instances
By default, MessageBubbleConfigService is a root-level singleton — all message bubbles share the same configuration. If you need different bubble customizations for different message lists (e.g., a main chat vs. a thread panel), create a wrapper component that provides its own instance:
See CometChatMessageList — Multiple Message Lists with Different Configurations for a complete example.
BubblePart Type
CSS Customization
Styling with CSS Variables
The Message Bubble component uses CSS variables for consistent theming. Override these variables to customize the appearance:
Dark Theme
Component-Specific Styling
Target specific bubble elements using BEM class names:
Advanced Usage
Group Conversation with Avatar and Sender Name
With Text Formatters
With Message Translation
Accessibility
The Message Bubble component is fully accessible and follows WCAG 2.1 Level AA guidelines:
Keyboard Support
| Key | Action |
|---|
Tab | Navigate between interactive elements |
Enter / Space | Activate focused element (avatar, options menu, reactions) |
Escape | Close options menu and return focus to bubble |
Arrow Keys | Navigate within options menu when open |
ARIA Attributes
| Attribute | Element | Purpose |
|---|
role="article" | Wrapper | Identifies message as an article |
aria-label | Wrapper | Describes message sender and type |
aria-describedby | Wrapper | Links to message content |
role="status" | Status info | Identifies status area |
aria-live="polite" | Status info | Announces status changes |
role="button" | Interactive elements | Identifies clickable elements |
aria-pressed | Reactions | Indicates if user has reacted |
role="group" | Reactions container | Groups related reactions |
Screen Reader Announcements
The component provides meaningful announcements for:
- Message sender and type
- Message status (sent, delivered, read)
- Edited messages
- Reactions and their counts
- Thread reply counts
Best Practices
Use the group property to enable avatar and sender name display in group conversations.
Always provide the complete CometChat message object to ensure proper rendering of all message types.
The component automatically determines the appropriate bubble component based on message type. Use contentView only when you need custom rendering.
Handle optionClick events to implement message actions like reply, copy, delete, etc.
When using custom templates, ensure you maintain accessibility by including proper ARIA attributes and keyboard navigation.
Use CSS variables for styling to ensure your customizations work correctly with both light and dark themes.