Skip to main content

Overview

The CometChatMessageComposer is a feature-rich Angular component for composing and sending messages in chat applications. It provides a comprehensive set of features including text input, file attachments, emoji picker, voice recording, @mentions, and optional rich text editing capabilities similar to Slack. The component follows a Service-Based Architecture where:
  • MessageComposerService handles all SDK interactions for sending messages, typing indicators, and file uploads
  • RichTextEditorService manages rich text editing functionality when enabled (custom implementation using native browser APIs)
  • Component @Input properties provide extensive customization options
  • Angular Signals power reactive state management for optimal performance

Key Features

  • Auto-Expanding Text Input: Textarea that grows with content up to a configurable maximum height
  • Attachments: Support for images, videos, audio, and files (selected files are sent directly)
  • Rich Text Editing: Optional rich text formatting using custom RichTextEditorService (bold, italic, lists, code blocks, etc.)
  • Emoji Picker: Built-in emoji keyboard with category navigation
  • Voice Recording: Record and send audio messages with waveform visualization
  • @Mentions: Tag users in messages with autocomplete suggestions
  • Reply & Edit Modes: Reply to specific messages or edit existing ones
  • Full Accessibility: WCAG 2.1 Level AA compliant with keyboard navigation and screen reader support
  • Extensive Customization: Template inputs for all UI sections
  • Lightweight: No external rich text editor dependencies (100KB+ smaller bundle)
Live Preview — default message composer preview. Open in Storybook ↗

Basic Usage

Simple Implementation with User

Simple Implementation with Group

With Rich Text Editing

With Attachments

Attachments are enabled by default through the attachment button. Selected files are sent directly in the current build — there is no queued preview before sending.

Layout Modes

The CometChatMessageComposer supports two layout modes to accommodate different UI requirements and screen sizes.

Single-Line Layout (Default)

The single-line layout arranges elements horizontally in a row:
  • Attachment button on the left
  • Input area in the center (grows to fill available space)
  • Auxiliary buttons (emoji, stickers, voice) on the right
  • Send button on the far right
This layout is ideal for:
  • Desktop applications with ample horizontal space
  • Chat interfaces where vertical space is limited
  • Traditional messaging UIs similar to Slack or Teams

Multiline Layout

The multiline layout arranges elements vertically:
  • Input area at the top spanning full width
  • All action buttons in a horizontal row below (attachment, emoji, stickers, voice, send)
This layout is ideal for:
  • Mobile applications where horizontal space is limited
  • Interfaces where you want to maximize input area width
  • Chat UIs that prioritize typing space over button visibility

Dynamic Layout Switching

You can dynamically switch between layouts based on screen size or user preferences:

Layout with Rich Text Editing

Both layouts work seamlessly with rich text editing:
Note: All composer features (attachments, emoji picker, voice recording, mentions, etc.) work identically in both layouts. The only difference is the visual arrangement of elements.

Properties

Entity Configuration Properties

Layout Configuration Properties

Text Input Configuration Properties

Attachment Configuration Properties

Hide Option Properties

Mentions Configuration Properties

Rich Text Configuration Properties

Other Configuration Properties

Template Properties

Events

Usage Patterns

CometChatMessageComposer supports two usage patterns for receiving the active user or group context.
When used alongside cometchat-conversations, the composer automatically subscribes to ChatStateService. No explicit [user] or [group] input is needed — the component sends messages to the active conversation.
If you need to observe (itemClick) yourself, you must set the active conversation manually so the message components stay in sync:
This is the recommended approach. The composer stays in sync with the conversation list without manual wiring.

Advanced Usage

Threaded Replies

Set parentMessageId to make outgoing messages part of a thread. This controls the threaded send behavior (the thread parent for outgoing messages) — it does not render a quoted reply preview on its own.

Quoted Reply Preview

To show the visible quoted reply preview UI, set messageToReply. This drives the preview and works with (closePreview). Note that parentMessageId alone does not render the quoted preview — messageToReply is what drives the preview plus the closePreview event.

Edit Mode

Enable edit mode by setting the messageToEdit property:

Rich Text Editing

Enable Slack-like rich text editing with formatting toolbar using the custom RichTextEditorService:
Rich Text Toolbar Features:
  • Bold (Ctrl+B / Cmd+B): Make text bold
  • Italic (Ctrl+I / Cmd+I): Make text italic
  • Underline (Ctrl+U / Cmd+U): Underline text
  • Strikethrough: Strike through text
  • Inline Code: Format as inline code
  • Link: Insert hyperlinks with validation
  • Ordered List: Create numbered lists
  • Bullet List: Create bulleted lists
  • Code Block: Insert code blocks
  • Blockquote: Add quoted text
Implementation Details:
  • Uses custom RichTextEditorService built on native browser APIs
  • No external dependencies
  • Smaller bundle size (100KB+ reduction)
  • Full keyboard shortcut support
  • XSS protection with HTML sanitization
  • Unicode and emoji support
  • Undo/redo with history grouping (500ms delay)

Rich Text Enhancements

The message composer includes advanced rich text features for improved user experience:

Floating Bubble Menu

Enable a Slack-like floating bubble menu that appears when text is selected (Web/Desktop only):
Bubble Menu Features:
  • Appears only when text is selected
  • Automatically disabled on mobile/touch devices
  • Quick access to formatting: bold, italic, underline, strikethrough, link
  • Smart positioning above selected text
  • Keyboard support (Escape to close)
  • Smooth fade in/out animations

Always-Visible Toolbar

Keep the formatting toolbar visible at all times for improved discoverability.
Benefits:
  • Toolbar remains visible even when editor is empty
  • Improved discoverability of formatting options
  • Consistent UI with no layout shifts
  • Ideal for professional/business contexts

Combining All Features

Use all rich text enhancements together:
This configuration provides:
  • Floating bubble menu for quick text selection formatting
  • Full keyboard shortcut support

@Mentions with Custom Request Builder

Configure mentions with custom user/member fetching:

File Attachments

Attachments are handled through the attachment button. Selected files are sent directly (there is no queued preview in the current build). Use the (error) output to surface any send failures:

Voice Recording

The composer includes built-in voice recording functionality:
When the microphone button is clicked:
  1. The CometChatMediaRecorder component appears
  2. User can record audio with waveform visualization
  3. Recording duration is displayed
  4. User can cancel or complete the recording
  5. Completed recordings are sent as audio messages

Customization with Templates

Custom Send Button

Custom Header View (Reply/Edit Preview)

Custom Auxiliary Buttons

Add custom action buttons alongside the default emoji and voice buttons:

Keyboard Accessibility

CometChatMessageComposer is fully keyboard accessible and meets WCAG 2.1 Level AA standards.

Keyboard Shortcuts

Accessibility Features

ARIA Attributes:
  • role="textbox" with aria-multiline="true" on the text input
  • aria-label describing the input purpose
  • aria-haspopup="menu" and aria-expanded on attachment button
  • aria-haspopup="dialog" and aria-expanded on emoji button
  • aria-label="Send message" on send button
  • aria-label and aria-pressed on voice recording button
  • role="menu" with role="menuitem" for attachment options
  • role="listbox" with role="option" for mention suggestions
  • role="toolbar" on rich text toolbar with proper button labels
Screen Reader Support:
  • Announces reply/edit preview when shown via aria-live="polite"
  • Announces recording state changes via aria-live="assertive"
  • Announces message sent confirmation via aria-live="polite"
  • Announces attachment added/removed via aria-live="polite"
  • Announces errors via aria-live="assertive"
Focus Management:
  • Visible focus indicators (2px border) meeting WCAG contrast requirements
  • Logical tab order through interactive elements
  • Focus returns to input after closing popups
  • Focus trap within menus when open
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

Styling with CSS Variables

The CometChatMessageComposer component uses CSS variables for comprehensive theming:

Dark Theme Example

Custom Brand Colors

Text Formatters

The component supports custom text formatters for automatic text transformation and metadata extraction.

Built-in Formatters

CometChatMentionsFormatter:
  • Detects @mention patterns in text
  • Highlights mentions with distinct styling
  • Extracts mention metadata (user ID, name, position)
  • Supports @all mentions for groups
CometChatUrlFormatter:
  • Detects URL patterns (http://, https://, www.)
  • Converts URLs to clickable links
  • Opens links in new tabs
  • Extracts URL metadata

Using Custom Formatters

Error Handling

The component provides comprehensive error handling through the error event:
For troubleshooting tips, see the Troubleshooting Guide.

Troubleshooting

Issue: Enter key creates line breaks when I want it to send messages Solution: Set enterKeyBehavior to SendMessage:
Issue: I need a compact single-line input Solution: Use the single-line layout with maxHeight:
Issue: My custom toggle button is gone Solution: The built-in toggle was removed. Implement your own toggle control as shown in Scenario 3 above.

See Also