Skip to main content

Overview

The CometChatSearch component provides a unified search experience across conversations and messages. It combines a debounced search input, a filter chip bar, and two lazy-loaded result sections (conversations and messages) into a single, cohesive UI. The component follows a service-driven architecture:
  • SearchConversationsService handles conversation search queries, pagination, and real-time listener updates
  • SearchMessagesService handles message search queries, pagination, and attachment-type filtering
  • CometChatTemplatesService provides template resolution with a priority chain: @Input → service template → shared template → default
  • Component @Input properties allow per-instance overrides for scoping, filtering, and display

Key Features

  • Cross-Entity Search: Search across both conversations and messages simultaneously, or scope to one
  • 9 Filter Types: Audio, Documents, Groups, Photos, Videos, Links, Unread, Conversations, Messages
  • Scoped Search: Narrow results to a specific user (uid) or group (guid)
  • Debounced Input: 500ms debounce prevents excessive SDK calls while typing
  • Lazy-Loaded Sections: Conversation and message result lists use @defer for optimal initial load
  • Unified State Views: Single empty/error view when both sections report the same state
  • Template Customization: Override any section of conversation or message result items
  • Real-Time Updates: Conversation results update with new messages, typing indicators, and user status changes
  • Filter Chip Logic: Intelligent mutual exclusivity — content filters (Photos, Videos, etc.) are mutually exclusive with Links; conversation filters (Unread, Groups) can coexist

Architecture

Live Preview — default search component preview. Open in Storybook ↗

Basic Usage

Simple Implementation

Scoped Search (Within a User or Group)

When uid or guid is set, conversation filters (Unread, Groups, Conversations) are hidden automatically and only message results are shown.

Scoped to One Entity Type

Properties

Configuration Properties

Display Control Properties

Scoping Properties

Template Properties

Conversation Result Templates

Message Result Templates

State View Templates

Template resolution follows a priority chain: @Input template → CometChatTemplatesService search template → CometChatTemplatesService shared template → built-in default.

Events

Event Payload Types

Filter System

The search component includes a filter chip bar that allows users to narrow results by type. Filters are organized into two categories:

Conversation Filters

These filters affect the conversation results section:

Message Filters

These filters affect the message results section:

Filter Behavior Rules

  • When a conversation filter is active, only the conversations section renders
  • When a message filter is active, only the messages section renders
  • Content filters (Photos, Videos, Documents, Audio) are mutually exclusive with Links
  • Multiple conversation filters can coexist (e.g., Unread + Groups)
  • When no filters are active and a keyword is entered, both sections render
  • When uid or guid is set, conversation filters are hidden automatically

Limiting Available Filters

Pre-Selecting a Filter

Unified State Management

When both conversation and message sections are active, the component coordinates their empty/error states to avoid duplicate views: When only one scope is active (via searchIn, uid, or guid), that section handles its own empty/error states independently.

Advanced Usage

Custom Request Builders

Override the default SDK query builders for conversations and messages:

Custom Context Menu for Conversation Results

Handling Search Results for Navigation

A common pattern is navigating to the matched message within its conversation when a message result is clicked:

Customization with Templates

Custom Message Result Item

Override the entire message result row:

Custom Empty and Error States

Custom Initial View

Replace the default “Search for messages, conversations…” placeholder:

Keyboard Accessibility

CometChatSearch provides keyboard accessibility for the search input, filter bar, and result items.

Keyboard Shortcuts

Accessibility Features

ARIA Attributes:
  • role="search" on the main container
  • role="searchbox" on the search input
  • role="toolbar" on the filter bar
  • aria-pressed on filter chips indicating active state
  • aria-label on back button, search input, and clear button
  • aria-live="assertive" on empty and error state regions
  • role="list" and role="listitem" on result sections
Screen Reader Support:
  • Filter chip labels are localized via the translate pipe
  • State changes (empty, error) are announced via aria-live regions
  • Back button and clear button have descriptive aria-label attributes
Focus Management:
  • Search input auto-focuses on component load
  • Clear button restores focus to search input after clearing
  • Result items are focusable with tabindex="0" (message results)
  • Visible focus indicators meeting WCAG contrast requirements

Styling with CSS Variables

The component uses CometChat CSS variables for theming. Key variables:

Filter Chip Styling

Active filter chips use a dark pill style with white text and icons:

Error Handling

Built-in Error Handling

The component handles errors from both conversation and message search services:

Error State Behavior

  • If only one section errors while the other has results, the errored section shows its own error view with its section header
  • If both sections error, a single unified error view is shown without section headers
  • Custom errorView templates are used when provided

Complete Example

  • CometChatConversations: Full conversation list component (CometChatSearch uses CometChatConversationItem internally for conversation results)
  • CometChatSearchBar: Standalone search bar component (CometChatSearch has its own built-in search input)
  • CometChatMessageList: Message list component for displaying messages in a conversation
  • CometChatMessageHeader: Header component that pairs with search for navigation context

Technical Details

  • Standalone Component: Can be imported and used independently
  • Change Detection: Uses OnPush strategy for optimal performance
  • Lazy Loading: Child result components use @defer blocks for code splitting
  • Signal-Based State: Services use Angular signals for reactive state management
  • Debounced Search: 500ms debounce on the search input to reduce SDK calls
  • BEM CSS: Follows Block Element Modifier naming convention (cometchat-search__*)
  • Localization: All text uses the translate pipe for i18n support