Skip to main content

Overview

The CometChatConversationItem component is a standalone Angular component designed to render a single conversation item. It is part of the enterprise refactoring that decomposes the monolithic CometChatConversations component into smaller, focused pieces. This component provides:
  • State Management: Support for active, selected, focused, and unread states
  • Slot-Based Customization: Fine-grained control over individual UI elements
  • Granular Events: Separate events for avatar, title, subtitle, timestamp, and badge clicks
  • Backward Compatibility: Section templates for existing implementations
  • Full Accessibility: ARIA labels, roles, and keyboard navigation support

Key Features

  • Standalone Component: Can be used independently or within CometChatConversations
  • 11 Customization Slots: Override specific UI elements without affecting others
  • 8 Granular Events: Respond to precise user interactions
  • Display Configuration: Hide receipts, user status, or group type icons
  • Context Menu Support: Customizable actions for each conversation
  • Pin Marker: Marks a pinned conversation in the trailing area, alongside the unread badge
  • OnPush Change Detection: Optimized for performance

Pinned Conversations

A conversation the user has pinned is marked in the row’s trailing area. The state is derived from the conversation itself — there is no input for it:
The presence of pinnedAt is the boolean; an unpinned conversation carries no key at all, so this is never “pinned at 0”. isPinned() covers both a personal pin and an app-wide one, and the accessor is optional-called because older Chat SDK builds do not expose it. The marker itself is aria-hidden, so the state reaches screen readers through the row’s accessible label instead — otherwise pinned and unpinned rows would be indistinguishable without sight. Pinning is performed from CometChatConversations, which also owns the ordering.

Basic Usage

Simple Implementation

Live Preview — interact with the component directly in the embed below. Open in Storybook ↗

With State Management

Properties

Required Input Properties

State Input Properties

Live Preview — all states (default, active, selected, focused, unread) side by side. Open in Storybook ↗

Display Configuration Properties

Customization Properties

Section Template Properties (Backward Compatibility)

Events

Slot-Based Customization

The component supports 11 slots via the ConversationSlots interface, organized into three sections:

Slot Overview

Slot Context

All slot templates receive a ConversationSlotContext object:
Some slots receive additional context properties:
  • statusIndicator: { status: string } - User status (‘online’, ‘offline’)
  • groupTypeIcon: { groupType: string } - Group type (‘public’, ‘private’, ‘password’)
  • title: { title: string } - Display name
  • subtitle: { subtitle: string } - Last message preview
  • timestamp: { timestamp: number } - Unix timestamp
  • unreadBadge: { count: number } - Unread count
  • receipt: { receiptStatus: string } - Receipt status

Custom Avatar Slot Example

Custom Unread Badge Slot Example

Custom Timestamp Slot Example

Event Handling

Granular Click Events

The component emits separate events for each clickable element, allowing precise handling:

Selection Mode

Handle selection events for multi-select scenarios:

Styling with CSS Variables

The CometChatConversationItem component uses CSS variables for comprehensive theming:

Dark Theme Example

Custom Brand Colors

Accessibility

The CometChatConversationItem component includes comprehensive accessibility features:

ARIA Attributes

  • role="listitem" on the conversation item container
  • aria-selected indicates selection state
  • aria-label with conversation name and unread count
  • role="status" on status indicators and badges
  • role="img" on group type icons with appropriate labels

Keyboard Navigation

Screen Reader Support

The component announces:
  • Conversation name
  • Unread message count (e.g., “5 unread messages”)
  • Online/offline status for user conversations
  • Group type for group conversations (private, password-protected)

Focus Management

  • Clear focus indicators using CSS box-shadow
  • Focus state is visually distinct from hover and active states
  • Supports high contrast mode

Integration with CometChatConversations

The CometChatConversationItem is designed to work seamlessly within CometChatConversations:
For advanced customization, you can provide a custom itemView template that uses CometChatConversationItem:

Best Practices

Use slot-based customization for targeted changes to specific UI elements. This keeps default behavior for other elements and reduces code complexity.
When handling granular click events (avatarClick, titleClick, etc.), the component automatically calls stopPropagation() to prevent the main itemClick event from firing. Design your event handlers accordingly.
The component uses OnPush change detection strategy. If you’re passing objects that change internally, ensure you create new object references to trigger change detection.
  • CometChatConversations: Parent component that renders a list of conversation items
  • CometChatAvatar: Avatar component used in the leading section
  • CometChatDate: Date formatting component used for timestamps
  • CometChatContextMenu: Context menu component for conversation actions

Technical Details

  • Standalone Component: Can be imported and used independently
  • Change Detection: Uses OnPush strategy for optimal performance
  • Bundle Size: Lightweight, focused component
  • Dependencies: CometChatAvatar, CometChatDate, CometChatContextMenu, TranslatePipe
  • BEM CSS: Follows Block Element Modifier naming convention
  • Accessibility: WCAG 2.1 Level AA compliant