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

PropertyTypeDefaultDescription
searchInCometChatSearchScope[][] (both)Scopes to search in. Empty array means both Conversations and Messages
searchFiltersCometChatSearchFilter[][Audio, Documents, Groups, Photos, Videos, Links, Unread]Filter chips to display in the filter bar
initialSearchFilterCometChatSearchFilterundefinedFilter that should be active by default when the component loads
defaultSearchTextstringundefinedPre-fill the search input and immediately trigger a search on load
conversationsRequestBuilderConversationsRequestBuilderundefinedCustom request builder for conversation search queries
messagesRequestBuilderMessagesRequestBuilderundefinedCustom request builder for message search queries
conversationOptions(conv: Conversation) => CometChatOption[]undefinedFunction to provide custom context menu options for conversation results
textFormattersCometChatTextFormatter[][]Custom text formatters for message content display
messageSentAtDateTimeFormatCalendarObjectundefinedCustom date/time format for message timestamps

Display Control Properties

PropertyTypeDefaultDescription
hideBackButtonbooleanfalseHide the back navigation button in the header
hideGroupTypebooleanfalseHide group type icons (public, private, password) in conversation results
hideUserStatusbooleanfalseHide user online/offline status indicator in conversation results
hideReceiptsbooleanfalseHide message read receipts (sent, delivered, read) in conversation results

Scoping Properties

PropertyTypeDefaultDescription
uidstringundefinedScope search to messages with a specific user. Hides conversation results and conversation filters
guidstringundefinedScope search to messages within a specific group. Hides conversation results and conversation filters

Template Properties

Conversation Result Templates

PropertyTypeContextDescription
conversationItemViewTemplateRef{ $implicit: Conversation }Custom template for the entire conversation result item
conversationLeadingViewTemplateRef{ $implicit: Conversation }Custom template for the leading section (avatar area)
conversationTitleViewTemplateRef{ $implicit: Conversation }Custom template for the title section
conversationSubtitleViewTemplateRef{ $implicit: Conversation }Custom template for the subtitle section (last message preview)
conversationTrailingViewTemplateRef{ $implicit: Conversation }Custom template for the trailing section (timestamp, badges)

Message Result Templates

PropertyTypeContextDescription
messageItemViewTemplateRef{ $implicit: BaseMessage }Custom template for the entire message result item
messageLeadingViewTemplateRef{ $implicit: BaseMessage }Custom template for the leading section (type-specific icon)
messageTitleViewTemplateRef{ $implicit: BaseMessage }Custom template for the title section (conversation/sender name)
messageSubtitleViewTemplateRef{ $implicit: BaseMessage }Custom template for the subtitle section (message content)
messageTrailingViewTemplateRef{ $implicit: BaseMessage }Custom template for the trailing section (timestamp, image/video thumbnail)

State View Templates

PropertyTypeDescription
initialViewTemplateRefShown before any search is performed (no keyword, no filters)
loadingViewTemplateRefShown while search results are being fetched (shimmer placeholders by default)
emptyViewTemplateRefShown when search returns no results
errorViewTemplateRefShown when a search operation fails
Template resolution follows a priority chain: @Input template → CometChatTemplatesService search template → CometChatTemplatesService shared template → built-in default.

Events

EventPayload TypeDescription
backClickvoidEmitted when the back button is clicked
conversationClickSearchConversationClickEventEmitted when a conversation result is clicked. Payload includes conversation and searchKeyword
messageClickSearchMessageClickEventEmitted when a message result is clicked. Payload includes message and searchKeyword
searchErrorCometChat.CometChatExceptionEmitted when a search operation fails in either section

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:
FilterEnum ValueBehavior
UnreadCometChatSearchFilter.UnreadShows only conversations with unread messages
GroupsCometChatSearchFilter.GroupsShows only group conversations
ConversationsCometChatSearchFilter.ConversationsShows all conversations (explicit scope)

Message Filters

These filters affect the message results section:
FilterEnum ValueBehavior
PhotosCometChatSearchFilter.PhotosShows only image messages
VideosCometChatSearchFilter.VideosShows only video messages
DocumentsCometChatSearchFilter.DocumentsShows only file/document messages
AudioCometChatSearchFilter.AudioShows only audio messages
LinksCometChatSearchFilter.LinksShows only messages containing links
MessagesCometChatSearchFilter.MessagesShows all message types (explicit scope)

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:
Conversations StateMessages StateResult
EmptyEmptySingle unified empty view (no section headers)
EmptyLoadedConversations section hidden entirely; messages shown normally
LoadedEmptyMessages section hidden entirely; conversations shown normally
ErrorErrorSingle unified error view (no section headers)
ErrorLoadedConversations shows error with header; messages shown normally
LoadedErrorConversations shown normally; messages shows error with header
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

KeyActionContext
TabNavigate between search input, filter chips, and result itemsGlobal
Shift + TabNavigate backwardsGlobal
EnterActivate focused result item or filter chipWhen focused
SpaceToggle filter chip or activate result itemWhen focused
EscapeClear search text and active filtersWhen search input is focused

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