Skip to main content

Overview

The CometChatMessageList component displays a real-time list of messages for the active conversation. It is a composite component that effectively manages real-time operations and includes various types of messages such as Text Messages, Media Messages, Stickers, and more. The component follows a Hybrid Approach architecture where:
  • MessageListService handles all SDK interactions, state management, and real-time updates
  • Component @Input properties allow developers to override service behavior for flexibility
  • Both service methods and @Input properties are available, with @Input taking priority when provided

Key Features

  • Real-time Updates: Automatic updates for new messages, message edits, deletions, and reactions
  • Date Separators: Automatic date separators between messages from different days
  • Sticky Date Header: Shows the current date while scrolling through messages
  • Scroll to Bottom: Button to quickly scroll to the latest messages
  • Smart Replies: AI-powered reply suggestions based on conversation context
  • Conversation Starters: AI-generated conversation starters for empty conversations
  • Message Options: Customizable context menu with actions like edit, delete, reply, forward
  • Reactions: Support for message reactions with emoji picker
  • Text Formatters: Extensible text formatting for mentions, links, and custom patterns
  • Keyboard Navigation: Full keyboard accessibility (WCAG 2.1 Level AA compliant)
  • Sound Notifications: notification sounds for new messages
Live Preview — default message list preview. Open in Storybook ↗

Basic Usage

Simple Implementation

The most basic usage requires only a user or group input to display messages:

With Group Conversation

Display messages for a group conversation:

Complete Chat Interface

Combine with MessageHeader and MessageComposer for a complete chat experience:

Thread View

Display messages in a thread context:

With Custom Messages Request Builder

Filter messages using a custom request builder:
To fetch messages for a specific entity, you need to provide either a User or Group object. The component will not display any messages without one of these inputs.
The following parameters in messagesRequestBuilder will always be overridden by the component:
  1. UID (set from the user input)
  2. GUID (set from the group input)

API Reference

This section provides a complete reference of all @Input properties, @Output events, and public methods available in the CometChatMessageList component.

Properties

Data Configuration Properties

Display Control Properties

Custom View Properties (Templates)

Date Format Properties

AI Feature Properties

Events

Methods

The following public methods are available on the CometChatMessageList component instance:

Scroll Methods

Example: Scroll to Bottom
Example: Scroll to Specific Message

Refresh Methods

Example: Refresh Messages

Smart Replies Methods

Example: Integrate with Message Composer

Translation Methods

Example: Translation

Delete Methods

Flag Methods

Utility Methods

CalendarObject Interface

The CalendarObject interface is used for date format configuration:
Example: Custom Date Formats

MessageListAlignment Enum

MessageBubbleAlignment Enum

Usage Examples for Complex Properties

Custom Text Formatters

Handling Events

Customization

The CometChatMessageList component provides extensive customization options to match your application’s design and functionality requirements. This section covers all customization approaches available.

Customization Approaches

CometChat UIKit offers multiple ways to customize the message list:

Props-Based Customization

The simplest way to customize the message list is through component @Input properties. These allow you to control behavior and appearance for a specific component instance.

Hiding UI Elements

Control which UI elements are visible:

Message Alignment

Change how messages are aligned in the list:

Custom Date Formats

Customize how dates are displayed:

Custom Empty, Loading, and Error Views

Provide custom templates for different states:

Service-Based Customization

For global customization that applies to all message list instances, use the MessageBubbleConfigService. This service allows you to configure message bubble views globally or per message type.

Understanding MessageBubbleConfigService

The service provides centralized configuration for message bubble views:

Setting Type-Specific Views

Customize views for specific message types:

Setting Global Views

Apply customizations to all message types:

Batch Configuration

Configure multiple message types at once:

Clearing Configurations

Reset customizations when needed:

Multiple Message Lists with Different Configurations

By default, MessageBubbleConfigService and FormatterConfigService are provided at the root level (providedIn: 'root'), meaning all message list instances share the same configuration. This works well for most applications. However, if you need different bubble styles or formatters for different message lists (e.g., a main chat panel and a thread panel side by side), you can scope these services to a wrapper component using Angular’s hierarchical dependency injection.
Each <cometchat-message-list> already gets its own MessageListService instance automatically (the component provides it internally). The scoping technique below applies only to customization services like MessageBubbleConfigService and FormatterConfigService.
Usage with two independent panels:
The main panel’s MessageBubbleConfigService customizations (set at the root level) do not affect the thread panel, and vice versa. Angular’s DI hierarchy ensures each panel resolves its own service instance.
Services you can scope this way:
Do not scope ChatStateService — it is intentionally a singleton that tracks the app-wide active conversation. Scoping it would break cross-component state synchronization.

Custom Text Formatters

Text formatters allow you to process and transform message text content. They can detect patterns like mentions, URLs, hashtags, or custom patterns and apply formatting.

Understanding Text Formatters

Text formatters extend the CometChatTextFormatter base class:

Creating a Custom Hashtag Formatter

Creating a Custom Phone Number Formatter

Using Custom Formatters

Formatters are applied in order of their priority property (lower numbers run first). Each formatter receives the output of the previous formatter as its input.

Custom Message Options

Message options are the actions available in the context menu when interacting with a message (edit, delete, reply, forward, etc.). You can customize which options are shown using the hide* input properties.

Hiding Specific Options

Quick Options Count

Control how many options appear directly on the message bubble (without opening the context menu):

Handling Option Events

Listen to events when users interact with message options:

CSS Variable Customization

CometChat UIKit uses CSS variables for styling, making it easy to customize the appearance without modifying component code. Override these variables in your global styles or scoped to specific components.

Core CSS Variables

The following CSS variables affect the message list and message bubbles:

Customizing Message Bubble Colors

Customizing Message List Container

Customizing Message Bubbles


Theming (Light/Dark Mode)

CometChat UIKit supports both light and dark themes through CSS variables. The theme is controlled by the data-theme attribute on the root element.

Switching Themes

Dark Theme CSS Variables

The dark theme automatically overrides CSS variables when [data-theme="dark"] is set:

Custom Theme Example

Create a completely custom theme by overriding CSS variables:

System Theme Detection

Automatically match the user’s system theme preference:
Use CSS variables consistently throughout your application to ensure theme changes propagate correctly. Avoid hardcoding color values in component styles.

Complete Customization Example

Here’s a comprehensive example combining multiple customization approaches:

Usage Patterns

CometChatMessageList supports two usage patterns for receiving the active user or group context.
When used alongside cometchat-conversations, the message list automatically subscribes to ChatStateService. No explicit [user] or [group] input is needed — the component loads messages for the active conversation.
This is the recommended approach. The message list stays in sync with the conversation list without manual wiring.

Advanced Usage

This section covers advanced usage scenarios including thread views, reactions, and AI-powered features like smart replies and conversation starters.

Thread View

Thread view allows users to have focused conversations around a specific message. When a user clicks on a message’s thread indicator, you can display the thread replies in a separate view.

Basic Thread View Implementation

Display thread replies by setting the parentMessageId input:

Complete Thread Navigation Example

Implement a full thread navigation flow with main chat and thread panel:
When implementing thread view, consider using Angular’s animation module to create smooth slide-in/slide-out transitions for the thread panel.

Reactions

Reactions allow users to respond to messages with emoji. The message list component provides built-in support for displaying and interacting with reactions.

Basic Reactions Setup

Enable reactions in the message list:

Custom Reactions Request Builder

Configure how reactions are fetched using a custom request builder:

Handling Reaction Events Programmatically

Add or remove reactions programmatically:
The message list component automatically updates the UI when reactions are added or removed. You don’t need to manually refresh the message list after reaction operations.

AI Smart Chat Features

The message list component includes AI-powered features that enhance the chat experience: Smart Replies and Conversation Starters.

Smart Replies

Smart replies provide AI-generated response suggestions based on the last received message. They appear after a configurable delay when the message contains trigger keywords.

Conversation Starters

Conversation starters provide AI-generated suggestions to help users begin a conversation. They appear when the conversation is empty (no messages yet).

Complete AI Smart Chat Features Example

Combine smart replies and conversation starters for a full AI-enhanced chat experience:

AI Smart Chat Features Configuration Reference

AI Smart Chat Features Behavior

Smart Replies:
  • Appear after the configured delay when the last received message contains trigger keywords
  • Hidden when the user starts typing
  • Hidden when a message is sent
  • Display up to 4 AI-generated suggestions
Conversation Starters:
  • Appear only when the conversation is empty (no messages)
  • Hidden once any message is sent or received
  • Display up to 4 AI-generated suggestions
AI Smart Chat Features require the CometChat AI extension to be enabled in your CometChat dashboard. Without the extension, smart replies and conversation starters will not appear even when enabled in the component.
For the best user experience, consider adjusting the smartRepliesDelayDuration based on your use case. A shorter delay (3-5 seconds) works well for support chat, while a longer delay (10-15 seconds) may be better for casual conversations.

Accessibility

The CometChatMessageList component is designed with accessibility in mind, following WCAG 2.1 Level AA guidelines. This section covers keyboard navigation, ARIA attributes, screen reader support, and best practices for creating accessible chat experiences.

Keyboard Navigation

The message list component provides comprehensive keyboard support for users who navigate without a mouse. All interactive elements are keyboard accessible.

Keyboard Shortcuts Reference

Message List Navigation:
Context Menu Navigation:

Keyboard Navigation Example

Focus Management

The component implements proper focus management for a seamless keyboard experience:
  1. Focus Trapping in Modals: When dialogs (delete confirmation, flag message, etc.) are open, focus is trapped within the modal until it’s closed.
  2. Focus Restoration: When a modal or menu is closed, focus returns to the element that triggered it.
  3. Visible Focus Indicators: All focusable elements have visible focus indicators using CSS:
Always test keyboard navigation by unplugging your mouse and navigating through the entire chat interface using only the keyboard. Ensure all actions can be completed without a pointing device.

ARIA Attributes

The message list component uses ARIA (Accessible Rich Internet Applications) attributes to provide semantic information to assistive technologies.

ARIA Attributes Reference

ARIA Implementation Examples

Message List Container:
Interactive Buttons:
Context Menu:
Live Regions for Dynamic Content:
Modal Dialogs:

Generating Accessible Labels


Screen Reader Testing Guidance

Testing with screen readers is essential to ensure the message list is accessible to users with visual impairments. This section provides guidance for testing with popular screen readers.

Testing Checklist

Use this checklist when testing the message list with screen readers: Basic Navigation:
  • Can navigate to the message list using Tab key
  • Message list is announced as a list with item count
  • Each message is announced with sender, time, and content
  • Can navigate between messages using arrow keys (when focused)
  • Focus indicators are visible on all interactive elements
Message Content:
  • Text messages are read correctly
  • Image messages announce “Image” or image description
  • Video messages announce “Video” with duration if available
  • Audio messages announce “Audio” with duration if available
  • File attachments announce file name and type
  • Reactions are announced with emoji and count
Interactive Elements:
  • Buttons announce their purpose (e.g., “Reply”, “Forward”, “Delete”)
  • Context menu opens and announces options
  • Can navigate context menu with arrow keys
  • Escape key closes menus and returns focus
  • Thread replies button announces reply count
Dynamic Content:
  • New messages are announced when received
  • Typing indicators are announced
  • Error messages are announced immediately
  • Loading states are announced
Dialogs and Modals:
  • Dialogs are announced when opened
  • Focus moves to dialog when opened
  • Can navigate dialog with Tab key
  • Escape key closes dialog
  • Focus returns to trigger element when closed

Testing with NVDA (Windows)

Testing with VoiceOver (macOS)

Testing with VoiceOver (iOS)

Testing with TalkBack (Android)

Common Issues and Solutions


Accessibility Best Practices

Follow these best practices to ensure your chat implementation is accessible to all users.

Color and Contrast

Ensure sufficient color contrast for all text and interactive elements:

Text Alternatives

Provide text alternatives for all non-text content:

Reduced Motion Support

Respect user preferences for reduced motion:

Focus Management

Implement proper focus management for a seamless experience:

Semantic HTML

Use semantic HTML elements for better accessibility:

Error Handling

Provide accessible error messages:

Accessibility Testing Tools

Use these tools to validate accessibility:

Accessibility Compliance Checklist

Before releasing your chat implementation, verify:
  • Perceivable
    • All images have appropriate alt text
    • Color is not the only means of conveying information
    • Text has sufficient contrast (4.5:1 for normal, 3:1 for large)
    • Content is readable when zoomed to 200%
  • Operable
    • All functionality is keyboard accessible
    • Focus order is logical and intuitive
    • Focus indicators are visible
    • No keyboard traps exist
    • Users can pause, stop, or hide moving content
  • Understandable
    • Language is specified (lang attribute)
    • Error messages are clear and helpful
    • Labels and instructions are provided
    • Navigation is consistent
  • Robust
    • Valid HTML is used
    • ARIA attributes are used correctly
    • Content works with assistive technologies
    • Component works across different browsers
Accessibility is not a one-time task. Regularly test your implementation with real users who rely on assistive technologies, and incorporate their feedback into your development process.
Consider hiring accessibility consultants or conducting usability testing with users who have disabilities. Automated tools catch only about 30% of accessibility issues—manual testing is essential.

Performance

The CometChatMessageList component is designed for optimal performance, even with large message histories. This section covers optimization strategies, memory management, and performance benchmarks to help you build efficient chat experiences.

Optimization Tips

Follow these optimization strategies to ensure the best performance for your chat implementation.

1. Use OnPush Change Detection

The message list component uses OnPush change detection internally. Ensure your parent components also use OnPush where possible:

2. Optimize Custom Templates

When using custom templates, avoid expensive operations in template expressions:

3. Implement trackBy for Custom Lists

If you render additional lists within message templates, always use trackBy:

4. Lazy Load Media Content

Configure lazy loading for images and videos to improve initial render time:

5. Debounce Scroll Events

If you add custom scroll handlers, debounce them to prevent performance issues:

6. Optimize Text Formatters

Keep text formatters efficient by avoiding complex regex patterns:

7. Limit Message History

For very long conversations, consider limiting the message history:

8. Use Efficient Date Formatting

Prefer Angular’s built-in DatePipe over custom date formatting functions:

Memory Management

Proper memory management is crucial for long-running chat sessions. Follow these strategies to prevent memory leaks and optimize memory usage.

Understanding Memory Usage

The message list component manages memory for:

Cleanup on Component Destroy

The component automatically cleans up resources when destroyed. Ensure your custom code also cleans up:

Managing Media Attachments

For conversations with many media attachments, implement lazy loading and cleanup:

Conversation Switching

When switching between conversations, the component automatically:
  1. Clears the current message list
  2. Cancels pending message requests
  3. Removes event listeners for the previous conversation
  4. Loads messages for the new conversation

Memory Profiling

Use browser developer tools to monitor memory usage:

Performance Benchmarks

This section provides performance benchmarks and testing methodology to help you evaluate and optimize your implementation.

Benchmark Results

The following benchmarks were measured on a mid-range device (Intel i5, 8GB RAM, Chrome 120):

Performance by Message Count

Performance varies based on message complexity (text vs. media), device capabilities, and browser. These benchmarks represent typical scenarios with mixed message types.

Testing Methodology

Use this methodology to benchmark your implementation:

Browser DevTools Performance Analysis

Use Chrome DevTools to analyze performance:

Lighthouse Performance Audit

Run Lighthouse audits to get performance scores:

Mobile Performance Considerations

Mobile devices require additional optimization considerations:

Performance Monitoring in Production

Implement performance monitoring for production:

Performance Best Practices Summary

Follow this checklist to ensure optimal performance:

Initial Load Optimization

  • Use appropriate pagination limit (20-30 messages)
  • Implement lazy loading for media content
  • Use OnPush change detection strategy
  • Minimize initial bundle size

Runtime Optimization

  • Avoid expensive computations in templates
  • Use trackBy for all @for loops
  • Debounce scroll and resize event handlers
  • Keep text formatters simple and efficient

Memory Management

  • Clean up subscriptions on component destroy
  • Release blob URLs when no longer needed
  • Limit message history for long conversations
  • Monitor memory usage in production

Mobile Optimization

  • Reduce page size for mobile devices
  • Implement touch-optimized interactions
  • Consider offline support for poor connectivity
  • Test on actual mobile devices

Monitoring

  • Implement performance metrics collection
  • Set up alerts for performance degradation
  • Regularly run Lighthouse audits
  • Profile with browser DevTools
Performance optimization is an ongoing process. Regularly profile your application, especially after adding new features or updating dependencies. Set performance budgets and monitor them in your CI/CD pipeline.
Avoid premature optimization. Focus on the most impactful optimizations first (pagination, lazy loading, change detection) before micro-optimizing. Always measure before and after changes to verify improvements.
For troubleshooting tips, see the Troubleshooting Guide.

Code Examples

This section provides comprehensive, copy-paste ready code examples for common use cases with the CometChatMessageList component. Each example includes complete setup code, imports, and detailed comments explaining the implementation.

Basic Setup Example

This example demonstrates the complete setup process for integrating CometChatMessageList into your Angular application, including CometChat initialization, user login, and component configuration.
Security Note: The examples above use Auth Key for simplicity. In production applications:
  1. Generate authentication tokens on your server
  2. Use CometChatUIKit.loginWithAuthToken(authToken) instead of CometChatUIKit.login(uid)
  3. Never expose your Auth Key in client-side code

Setup Checklist

Before running the examples, ensure you have completed these steps:
1

Create CometChat Account

Sign up at cometchat.com and create a new app to get your App ID, Region, and Auth Key.
2

Install Dependencies

3

Update Configuration

Replace placeholder values in the code:
  • YOUR_APP_ID → Your CometChat App ID
  • YOUR_REGION → Your region (us, eu, in, etc.)
  • YOUR_AUTH_KEY → Your Auth Key
  • CURRENT_USER_ID → The logged-in user’s ID
  • RECEIVER_USER_ID → The user ID to chat with
4

Create Test Users

Create test users in your CometChat dashboard or via the API:
5

Run Your Application

Common Configuration Options

Here are the most commonly used configuration options for the message list:
Start with the minimal setup and progressively add features as needed. This approach helps you understand each configuration option and troubleshoot issues more easily.