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
- Multiple Attachments: Support for images, videos, audio, and files with drag-and-drop
- 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 and Drag-Drop
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
- 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)
- 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:Properties
Entity Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
user | CometChat.User | undefined | The user to send messages to (for 1-on-1 conversations). Mutually exclusive with group. |
group | CometChat.Group | undefined | The group to send messages to (for group conversations). Mutually exclusive with user. |
parentMessageId | number | undefined | Parent message ID for threaded replies. When set, messages are sent as replies. |
Layout Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
layout | 'single-line' | 'multiline' | 'single-line' | Layout mode for the composer. 'single-line' arranges elements horizontally (attachment button on left, input in center, auxiliary buttons on right). 'multiline' arranges elements vertically (input area on top spanning full width, all buttons in a row below). |
Text Input Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
placeholderText | string | 'message_composer_placeholder' | Placeholder text for the input area (localization key) |
initialComposerText | string | '' | Initial text to pre-fill in the composer |
text | string | '' | Controlled text value for the composer |
maxHeight | number | 200 | Maximum height for the text input area in pixels |
enterKeyBehavior | EnterKeyBehavior | SendMessage | Behavior when Enter is pressed: SendMessage, NewLine, or None |
Attachment Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
attachmentOptions | CometChatMessageComposerAction[] | undefined | Custom attachment options for the attachment menu |
maxAttachments | number | 10 | Maximum number of attachments allowed |
allowedFileTypes | string[] | undefined | Allowed MIME types for attachments (e.g., ['image/*', 'application/pdf']) |
maxFileSize | number | undefined | Maximum file size in bytes |
showAttachmentPreview | boolean | true | Show attachment preview thumbnails before sending |
enableDragDrop | boolean | true | Enable drag-and-drop file uploads |
Hide Option Properties
| Property | Type | Default | Description |
|---|---|---|---|
hideAttachmentButton | boolean | false | Hide the attachment button |
hideImageAttachmentOption | boolean | false | Hide image option in attachment menu |
hideVideoAttachmentOption | boolean | false | Hide video option in attachment menu |
hideAudioAttachmentOption | boolean | false | Hide audio option in attachment menu |
hideFileAttachmentOption | boolean | false | Hide file option in attachment menu |
hidePollsOption | boolean | false | Hide polls option in attachment menu |
hideCollaborativeDocumentOption | boolean | false | Hide collaborative document option |
hideCollaborativeWhiteboardOption | boolean | false | Hide collaborative whiteboard option |
hideEmojiKeyboardButton | boolean | false | Hide the emoji picker button |
hideVoiceRecordingButton | boolean | false | Hide the voice recording button |
hideStickersButton | boolean | false | Hide the stickers button |
hideLiveReaction | boolean | false | Hide the live reaction button |
hideSendButton | boolean | false | Hide the send button |
Mentions Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
disableMentions | boolean | false | Disable @mentions functionality |
disableMentionAll | boolean | false | Disable @all mention option in groups |
mentionAllLabel | string | 'all' | Label for the @all mention option |
mentionsUsersRequestBuilder | CometChat.UsersRequestBuilder | undefined | Custom request builder for fetching users for mentions |
mentionsGroupMembersRequestBuilder | CometChat.GroupMembersRequestBuilder | undefined | Custom request builder for fetching group members for mentions |
Rich Text Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
enableRichText | boolean | true | Enable rich text editing. When disabled, toolbar toggle button is hidden and pasting/adding content won’t apply rich text formatting. Mentions and other formatters still work independently. |
hideRichTextToolbar | boolean | false | Hide the rich text formatting toolbar. When showToolbarToggle is enabled, the toggle overrides this setting. |
showBubbleMenuOnSelection | boolean | true | Show floating bubble menu when text is selected (Web/Desktop only) |
showToolbarToggle | boolean | true | Show a toggle button to show/hide the fixed toolbar. Emits toolbarToggleClick with ‘active’ or ‘inactive’ state. |
Other Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
disableTypingEvents | boolean | false | Disable sending typing indicator events |
disableSoundForMessage | boolean | false | Disable sound when sending messages |
customSoundForMessage | string | undefined | Custom sound URL for message sent notification |
liveReactionIcon | string | undefined | Custom icon for live reaction button |
messageToEdit | CometChat.BaseMessage | undefined | Message to edit (enables edit mode) |
messageToReply | CometChat.BaseMessage | undefined | Message to reply to (enables reply preview) |
textFormatters | CometChatTextFormatter[] | undefined | Array of text formatters to apply |
showToolbarToggle | boolean | true | Whether to show the toolbar toggle button for expanding/collapsing the action toolbar |
Template Properties
| Property | Type | Default | Description |
|---|---|---|---|
headerView | TemplateRef<any> | undefined | Custom template for the header section above the input |
footerView | TemplateRef<any> | undefined | Custom template for the footer section below the input |
sendButtonView | TemplateRef<any> | undefined | Custom template for the send button |
auxiliaryButtonView | TemplateRef<any> | undefined | Custom template for auxiliary action buttons |
secondaryButtonView | TemplateRef<any> | undefined | Custom template for secondary action buttons |
attachmentIconView | TemplateRef<any> | undefined | Custom template for the attachment icon |
voiceRecordingIconView | TemplateRef<any> | undefined | Custom template for the voice recording icon |
emojiIconView | TemplateRef<any> | undefined | Custom template for the emoji icon |
Events
| Event | Payload Type | Description |
|---|---|---|
textChange | string | Emitted when the text content changes |
sendButtonClick | CometChat.BaseMessage | Emitted when a message is sent successfully |
error | CometChat.CometChatException | Emitted when an error occurs |
closePreview | void | Emitted when the reply/edit preview is closed |
attachmentAdded | File | Emitted when an attachment is added |
attachmentRemoved | File | Emitted when an attachment is removed |
mentionSelected | CometChat.User | CometChat.GroupMember | Emitted when a mention is selected |
Usage Patterns
CometChatMessageComposer supports two usage patterns for receiving the active user or group context.- Using Service
- Using Props
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.Advanced Usage
Reply Mode (Threaded Messages)
Enable reply mode by setting theparentMessageId to reply to a specific message:
Edit Mode
Enable edit mode by setting themessageToEdit property:
Rich Text Editing
Enable Slack-like rich text editing with formatting toolbar using the custom RichTextEditorService:- 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
- Uses custom
RichTextEditorServicebuilt 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):- 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:- 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:- Floating bubble menu for quick text selection formatting
- Toolbar toggle button for showing/hiding the fixed toolbar
- Full keyboard shortcut support
@Mentions with Custom Request Builder
Configure mentions with custom user/member fetching:File Attachments with Validation
Configure attachment handling with file type and size validation:Voice Recording
The composer includes built-in voice recording functionality:- The CometChatMediaRecorder component appears
- User can record audio with waveform visualization
- Recording duration is displayed
- User can cancel or complete the recording
- 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
| Key | Action | Context |
|---|---|---|
Tab | Navigate between interactive elements | Global |
Shift + Tab | Navigate backwards | Global |
Enter | Send message (when enterKeyBehavior is SendMessage) | Text input focused |
Shift + Enter | Insert new line | Text input focused |
Enter / Space | Activate focused button | When button is focused |
Escape | Close open popups (emoji, attachments, mentions) | When popup is open |
↓ (Down Arrow) | Navigate to next mention suggestion | When mentions panel is open |
↑ (Up Arrow) | Navigate to previous mention suggestion | When mentions panel is open |
Enter / Tab | Select focused mention | When mention is focused |
Ctrl + B | Toggle bold (rich text mode) | When rich text is enabled |
Ctrl + I | Toggle italic (rich text mode) | When rich text is enabled |
Ctrl + U | Toggle underline (rich text mode) | When rich text is enabled |
Accessibility Features
ARIA Attributes:role="textbox"witharia-multiline="true"on the text inputaria-labeldescribing the input purposearia-haspopup="menu"andaria-expandedon attachment buttonaria-haspopup="dialog"andaria-expandedon emoji buttonaria-label="Send message"on send buttonaria-labelandaria-pressedon voice recording buttonrole="menu"withrole="menuitem"for attachment optionsrole="listbox"withrole="option"for mention suggestionsrole="toolbar"on rich text toolbar with proper button labels
- 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"
- 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
- ✅ 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
- 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 theerror event:
For troubleshooting tips, see the Troubleshooting Guide.
Troubleshooting
Issue: Enter key creates line breaks when I want it to send messages Solution: SetenterKeyBehavior to SendMessage:
single-line layout with maxHeight:
See Also
- CometChatMessageList - Display messages in a conversation
- CometChatConversations - List of conversations
- RichTextEditorService API - Rich text editor service documentation
- Rich Text Formatting Guide - Comprehensive guide to rich text features