Skip to main content

Overview

The CometChatUsers component displays a real-time, scrollable list of users with support for search, selection modes, and extensive customization. It provides an integral search functionality, allowing you to locate any specific user swiftly and easily. For each user listed, the component displays the user’s name by default, in conjunction with their avatar when available. Furthermore, it includes a status indicator, visually informing you whether a user is currently online or offline. The component follows a Manager-based Architecture where:
  • UsersManager handles SDK request building and pagination
  • Component manages state, real-time listeners, and UI rendering
  • Templates allow extensive customization of all UI sections

Key Features

  • Real-time Updates: Automatic updates for user online/offline status changes
  • Flexible Customization: Extensive template projection for all UI sections
  • Selection Modes: Support for single and multiple user selection with shift-click range selection
  • Selected Users Preview: Display chips for selected users in multiple selection mode
  • Alphabetical Section Headers: Group users by first letter of name
  • Search Functionality: Built-in search with 300ms debouncing
  • Keyboard Navigation: Full keyboard accessibility with arrow keys and shortcuts (WCAG 2.1 Level AA compliant)
  • Context Menu: Customizable actions for each user
  • Error Handling: Comprehensive error handling with custom error views
Live Preview — default users list preview. Open in Storybook ↗

Keyboard Accessibility

CometChatUsers is fully keyboard accessible and meets WCAG 2.1 Level AA standards. All functionality can be accessed using only the keyboard.

Keyboard Shortcuts

Accessibility Features

ARIA Attributes:
  • role="list" on users container
  • role="listitem" on each user item
  • aria-label with user name and status
  • aria-selected indicates selected users
  • Proper tabindex management (roving tabindex pattern)
Screen Reader Support:
  • Announces user details when focused
  • Announces selection state changes
  • Announces online/offline status
  • Semantic HTML structure
Focus Management:
  • Visible focus indicators (2px border) meeting WCAG contrast requirements
  • Focus restoration after interactions
  • Roving tabindex for efficient keyboard navigation
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

Basic Usage

Simple Implementation

With Search and Section Headers

Properties

Display Control Properties

Data Configuration Properties

Customization Properties

Template Properties

Events

Usage Patterns

CometChatUsers supports two usage patterns for communicating the selected user to downstream components.
When a user is selected, ChatStateService stores the active user. Downstream components like cometchat-message-header, cometchat-message-list, and cometchat-message-composer automatically subscribe to the change.
This is the recommended approach. Selecting a user automatically updates all downstream message components.

Advanced Usage

Filtering Users with Request Builder

Use the usersRequestBuilder to filter users by various criteria:

UserRequestBuilder Methods

Selection Modes

Enable single or multiple user selection:

Shift-Click Range Selection

In multiple selection mode, users can use Shift+Click to select a range of users:
  1. Click on a user to set the anchor point
  2. Hold Shift and click on another user
  3. All users between the anchor and clicked user will be selected/deselected
This feature is built-in and requires no additional configuration.

Custom Context Menu Options

Provide custom actions for each user:

Customization with Templates

Custom Subtitle View

Customize the subtitle section to show additional user information:

Custom Leading View

Customize the avatar and status indicator area:

Custom Trailing View

Customize the trailing section with action buttons:

Custom Empty and Error States

Provide custom views for empty and error states:

Styling with CSS Variables

The CometChatUsers component uses CSS variables for comprehensive theming:

Dark Theme Example

Custom Brand Colors

Real-Time Features

Automatic Updates

The component automatically updates in real-time for:
  • User Status: Online/offline status changes are reflected immediately
  • User Blocked/Unblocked: Updates when users are blocked or unblocked via CometChatUserEvents
  • Connection Recovery: Automatically refreshes the list when connection is re-established

Event Subscriptions

The component subscribes to the following events:

Error Handling

Built-in Error Handling

The component includes comprehensive error handling:
For troubleshooting tips, see the Troubleshooting Guide.

Best Practices

Use usersRequestBuilder to limit the initial fetch size for better performance. The default limit is 30 users per page.
Always handle the error event to provide feedback to users when something goes wrong.
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 showSelectedUsersPreview with selectionMode="multiple" to provide visual feedback of selected users.
When using custom context menu options, ensure the onClick handlers are properly bound to avoid this context issues. Use arrow functions.

Complete Example

Here’s a comprehensive example combining multiple features:
  • CometChatGroups: List and select groups
  • CometChatConversations: Display conversations list
  • CometChatMessageList: Display messages for a selected user
  • CometChatAvatar: Avatar component used in user items
  • CometChatListItem: List item component used for rendering users

Technical Details

  • Standalone Component: Can be imported and used independently
  • Change Detection: Uses OnPush strategy for optimal performance
  • Manager Architecture: UsersManager handles SDK interactions
  • 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