Overview
The CometChatConversations component displays a real-time list of conversations (both user and group conversations) for the logged-in user. It provides a rich set of features including real-time updates, search functionality, selection modes, keyboard navigation, and extensive customization through templates and styling.
The component follows a Hybrid Approach architecture where:
- ConversationsService 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, typing indicators, and user status changes
- Flexible Customization: Extensive template projection for all UI sections
- Service-Based Architecture: Clean separation of concerns with Angular best practices
- Keyboard Navigation: Full keyboard accessibility with arrow keys and shortcuts (WCAG 2.1 Level AA compliant)
- Selection Modes: Support for single and multiple conversation selection
- Search Functionality: Built-in search with debouncing
- Context Menu: Customizable actions for each conversation
- Sound Notifications: Optional notification sounds for new messages
- Error Handling: Comprehensive error handling with retry logic
Keyboard Accessibility
CometChatConversations is fully keyboard accessible and meets WCAG 2.1 Level AA standards. All functionality can be accessed using only the keyboard.
Keyboard Shortcuts
| Key | Action | Context |
|---|
Tab | Navigate between UI elements | Global |
Shift + Tab | Navigate backwards | Global |
↓ (Down Arrow) | Focus next conversation | When list is focused |
↑ (Up Arrow) | Focus previous conversation | When list is focused |
Enter | Open/activate focused conversation | When conversation is focused |
Space | Toggle selection (in selection mode) or activate | When conversation is focused |
Escape | Clear selection and reset focus | When list is focused |
/ | Focus search bar | When search is enabled |
| Key | Action | Context |
|---|
Enter or Space | Open context menu | When more button is focused |
↓ (Down Arrow) | Focus next menu item | When menu is open |
↑ (Up Arrow) | Focus previous menu item | When menu is open |
Enter or Space | Select focused menu item | When menu item is focused |
Escape | Close menu | When menu is open |
Accessibility Features
ARIA Attributes:
role="list" on conversations container
role="listitem" on each conversation
aria-label with conversation details (name, last message, unread count)
aria-selected indicates selected conversations
aria-live="polite" region for screen reader announcements
- Proper
tabindex management (roving tabindex pattern)
Screen Reader Support:
- Announces conversation details when focused
- Announces selection state changes
- Announces when search bar is focused
- Live region for dynamic updates
- Semantic HTML structure
Focus Management:
- Visible focus indicators (2px border) meeting WCAG contrast requirements
- Focus trap within modals (delete confirmation)
- Focus restoration after closing overlays
- Roving tabindex for efficient keyboard navigation
- High contrast mode support
WCAG 2.1 Compliance:
- ✅ 2.1.1 Keyboard (Level A) - All functionality available via keyboard
- ✅ 2.1.2 No Keyboard Trap (Level A) - Users can navigate away using keyboard
- ✅ 2.4.3 Focus Order (Level A) - Logical focus order
- ✅ 2.4.7 Focus Visible (Level AA) - Visible focus indicators
- ✅ 4.1.2 Name, Role, Value (Level A) - Proper ARIA attributes
- ✅ 4.1.3 Status Messages (Level AA) - Screen reader announcements
Customizing Keyboard Behavior
The component’s keyboard handlers are scoped to the list container and won’t interfere with your application’s global keyboard shortcuts. If you need to disable specific shortcuts, handle this at the application level:
Basic Usage
Simple Implementation
With Custom Title and Search
Properties
Display Control Properties
| Property | Type | Default | Description |
|---|
hideReceipts | boolean | false | Hide message read receipts in conversation items |
hideError | boolean | false | Hide error views when errors occur |
hideDeleteConversation | boolean | false | Hide delete option in context menu |
hideUserStatus | boolean | false | Hide online/offline status indicators |
hideGroupType | boolean | false | Hide group type icons for group conversations |
showScrollbar | boolean | false | Show/hide scrollbar in conversation list |
showSearchBar | boolean | false | Show/hide search bar in header |
Data Configuration Properties
| Property | Type | Default | Description |
|---|
conversationsRequestBuilder | ConversationsRequestBuilder | undefined | Custom request builder for filtering and pagination |
activeConversation | Conversation | undefined | Currently active/highlighted conversation |
textFormatters | CometChatTextFormatter[] | [] | Custom text formatters for message previews |
selectionMode | SelectionMode | 'none' | Selection mode: 'none', 'single', or 'multiple' |
lastMessageDateTimeFormat | CalendarObject | undefined | Custom date/time format configuration |
Customization Properties
| Property | Type | Default | Description |
|---|
options | (conversation: Conversation) => CometChatOption[] | undefined | Function to provide custom context menu options |
disableDefaultContextMenu | boolean | true | When true, prevents the browser’s native context menu and shows the custom context menu instead |
slots | Partial<ConversationSlots> | undefined | Slot-based customization for fine-grained UI control of conversation items |
Sound Configuration Properties
| Property | Type | Default | Description |
|---|
disableSoundForMessages | boolean | false | Disable notification sounds for new messages |
customSoundForMessages | string | undefined | Custom sound URL for notifications |
Template Properties
| Property | Type | Default | Description |
|---|
headerView | TemplateRef<any> | undefined | Custom template for entire header section |
menuView | TemplateRef<any> | undefined | Custom template for menu area in the header (e.g., action buttons, 3-dot menu) |
loadingView | TemplateRef<any> | undefined | Custom template for loading state |
emptyView | TemplateRef<any> | undefined | Custom template for empty state |
errorView | TemplateRef<any> | undefined | Custom template for error state |
searchView | TemplateRef<any> | undefined | Custom template for search bar |
itemView | TemplateRef<{$implicit: Conversation}> | undefined | Custom template for entire conversation item |
leadingView | TemplateRef<{$implicit: Conversation}> | undefined | Custom template for leading section (avatar area) |
titleView | TemplateRef<{$implicit: Conversation}> | undefined | Custom template for title section |
subtitleView | TemplateRef<{$implicit: Conversation}> | undefined | Custom template for subtitle section (message preview) |
trailingView | TemplateRef<{$implicit: Conversation}> | undefined | Custom template for trailing section (timestamp, badges) |
Events
| Event | Payload Type | Description |
|---|
itemClick | CometChat.Conversation | Emitted when a conversation is clicked |
select | {conversation: Conversation, selected: boolean} | Emitted when a conversation is selected/deselected |
error | CometChat.CometChatException | Emitted when an error occurs |
searchBarClick | void | Emitted when search bar is clicked |
contextMenuOpen | CometChat.Conversation | Emitted when a context menu is opened on a conversation |
contextMenuClose | CometChat.Conversation | Emitted when a context menu is closed |
scrollToTop | void | Emitted when the list is scrolled to the top |
scrollToBottom | void | Emitted when the list is scrolled to the bottom |
selectionChange | SelectionState | Emitted when the selection state changes in selection mode |
Usage Patterns
CometChatConversations supports two usage patterns. The default service-based approach uses ChatStateService to automatically wire downstream components. Alternatively, you can pass data explicitly via @Input() bindings.
Using Service
Using Props
When a user clicks a conversation, ChatStateService stores the active user or group. Downstream components like cometchat-message-header, cometchat-message-list, and cometchat-message-composer automatically subscribe to state changes — no explicit prop passing required.This is the recommended approach for most applications. It reduces boilerplate and keeps components in sync automatically.
Pass [user] or [group] inputs directly to override ChatStateService state for each component instance. This is useful when you manage conversation selection yourself or render multiple chat panels.When [user] or [group] inputs are provided, they take priority over ChatStateService state for that component instance.
Advanced Usage
Filtering Conversations
Use the conversationsRequestBuilder to filter conversations by type, tags, or other criteria:
Selection Mode
Enable single or multiple conversation selection:
Provide custom actions for each conversation:
Customization with Templates
Custom Subtitle View
Customize the message preview section:
Custom Leading View with Status
Customize the avatar and status indicator:
Custom Empty and Error States
Provide custom views for empty and error states:
Slot-Based Customization
The slots input provides fine-grained control over individual UI elements within each conversation item. Unlike section-level templates (leadingView, subtitleView, etc.) which replace entire sections, slots let you override a single element — like just the avatar, just the unread badge, or just the timestamp — while keeping everything else at its default.
When to Use Slots vs Templates
| Approach | Replaces | Use when |
|---|
slots | A single element (e.g., just the avatar) | You want surgical control over one element |
leadingView / subtitleView / trailingView | An entire section | You want to redesign a whole area |
itemView | The entire conversation item | You want full control over the row |
Available Slots
Slots are organized into three sections of the conversation item:
Leading section (left side):
| Slot | Description |
|---|
avatar | The user/group avatar image |
statusIndicator | Online/offline status dot |
groupTypeIcon | Public/private/password group icon |
typingIndicator | Animated typing dots |
Body section (center):
| Slot | Description |
|---|
title | Conversation name (user or group) |
subtitle | Last message preview text |
subtitleReceipt | Receipt icon in the subtitle row |
Trailing section (right side):
| Slot | Description |
|---|
timestamp | Last message time |
unreadBadge | Unread message count badge |
receipt | Message receipt indicator (sent/delivered/read) |
contextMenuTrigger | The “more options” button |
ConversationSlotContext
Every slot template receives a ConversationSlotContext object as its implicit variable, plus any slot-specific extras:
Slots with extra context variables:
| Slot | Extra variable | Type |
|---|
statusIndicator | status | string ('online' | 'offline') |
groupTypeIcon | groupType | string ('public' | 'private' | 'password') |
title | title | string |
subtitle | subtitle | string |
subtitleReceipt | receiptStatus | string ('sent' | 'delivered' | 'read' | 'wait' | 'error') |
timestamp | timestamp | number (Unix seconds) |
unreadBadge | count | number |
receipt | receiptStatus | string |
Usage
Import the types:
Override a single slot
Override multiple slots
Slots and section templates can be combined. For example, use slots.avatar to customize just the avatar while using subtitleView to replace the entire subtitle section.
Slots are passed through to CometChatConversationItem internally. The slots input on CometChatConversations applies the same slots to every item in the list.
Service Configuration (Hybrid Approach)
The component supports both service-level and component-level configuration. Service configuration applies globally to all component instances, while component @Input properties override service settings for specific instances.
Global Service Configuration
Configure the ConversationsService to set defaults for all component instances:
Per-Instance Override
Override service configuration for specific component instances:
Setting Active Conversation
Set the active conversation globally or per-instance:
Styling with CSS Variables
The CometChatConversations component uses CSS variables for comprehensive theming:
Dark Theme Example
Custom Brand Colors
Accessibility
The CometChatConversations component includes comprehensive accessibility features to ensure usability for all users.
Keyboard Navigation
| Key | Action |
|---|
Tab | Move focus to/from the conversation list |
Arrow Down | Focus next conversation in the list |
Arrow Up | Focus previous conversation in the list |
Enter / Space | Select the focused conversation |
Escape | Clear selection or close open menus |
ARIA Support
The component includes proper ARIA attributes for screen reader compatibility:
role="list" on the conversation list container
role="listitem" on each conversation item
aria-label with conversation name and last message preview
aria-selected attribute based on selection state
aria-live="polite" for real-time updates announcements
tabindex management for keyboard navigation
Screen Reader Announcements
The component announces important state changes to screen readers:
- New message received: “New message from [User Name]”
- Conversation selected: “Conversation with [User Name] selected”
- Typing indicator: “[User Name] is typing”
- Error states: “Error loading conversations”
- Empty state: “No conversations available”
Focus Management
- Clear focus indicators using the primary color
- Focus is maintained when navigating with keyboard
- Focus returns to the last focused item after menu interactions
- Focus is trapped within modal dialogs (context menus)
High Contrast Mode
The component supports high contrast mode with enhanced visual indicators:
Reduced Motion
Respects user’s motion preferences:
Real-Time Features
Automatic Updates
The component automatically updates in real-time for:
- New Messages: Conversations move to the top when new messages arrive
- Message Updates: Edited or deleted messages update the preview
- Typing Indicators: Shows when users are typing
- User Status: Online/offline status updates in real-time
- Read Receipts: Updates when messages are read
- Unread Count: Badge updates automatically
Sound Notifications
Enable sound notifications for new messages:
The component includes built-in sound throttling (max 1 sound per 2 seconds) to prevent notification spam.
Typing Indicators
Typing indicators are shown automatically in the subtitle section:
Error Handling
Built-in Error Handling
The component includes comprehensive error handling:
Retry Logic
The service includes automatic retry logic with exponential backoff for recoverable errors:
- Network errors: Retries up to 3 times
- Timeout errors: Retries with increasing delays (1s, 2s, 4s)
- Authentication errors: No retry (requires user action)
Custom Error View
Provide a custom error view with retry functionality:
Best Practices
Use the service-based configuration for global settings and component @Input properties for instance-specific overrides. This provides maximum flexibility.
Always unsubscribe from observables in ngOnDestroy to prevent memory leaks. The component handles this automatically, but be careful with custom subscriptions.
The component uses OnPush change detection strategy for optimal performance. If you’re using custom templates with external state, ensure proper change detection triggering.
Use the trackBy function in custom templates when iterating over conversations to improve rendering performance.
When using custom context menu options, ensure the onClick handlers are properly bound to avoid this context issues. Use arrow functions or .bind(this).
The component automatically handles pagination when scrolling to the bottom. You don’t need to implement pagination logic manually.
Complete Example
Here’s a comprehensive example combining multiple features:
- CometChatMessageList: Display messages for a selected conversation
- CometChatUsers: List and select users to start conversations
- CometChatGroups: List and select groups to start conversations
- CometChatSearchBar: Search component used in the conversations header
- CometChatContextMenu: Context menu for conversation actions
- CometChatAvatar: Avatar component used in conversation items
Technical Details
- Standalone Component: Can be imported and used independently
- Change Detection: Uses
OnPush strategy for optimal performance
- Service Architecture: All SDK logic in ConversationsService
- Real-time Updates: Automatic via SDK listeners
- Pagination: Automatic on scroll with intersection observers
- Accessibility: WCAG 2.1 Level AA compliant
- BEM CSS: Follows Block Element Modifier naming convention
- Bundle Size: Optimized for production builds
Browser Compatibility
The CometChatConversations component is compatible with all modern browsers:
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
The component uses standard web APIs and RxJS for state management, ensuring broad compatibility.