Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-react-uikit-v7.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

{
  "component": "CometChatMessageComposer",
  "package": "@cometchat/chat-uikit-react",
  "import": "import { CometChatMessageComposer } from \"@cometchat/chat-uikit-react\";",
  "cssImport": "import \"@cometchat/chat-uikit-react/css-variables.css\";",
  "description": "Rich text input with attachments, emoji, voice recording, mentions, and formatting for sending messages.",
  "cssRootClass": ".cometchat-message-composer",
  "primaryOutput": {
    "prop": "onSendButtonClick",
    "type": "(message: CometChat.BaseMessage, mode?: 'send' | 'edit') => void"
  },
  "props": {
    "entity": {
      "user": { "type": "CometChat.User", "default": "undefined" },
      "group": { "type": "CometChat.Group", "default": "undefined" },
      "parentMessageId": { "type": "number", "default": "undefined" }
    },
    "layout": {
      "layout": {
        "type": "CometChatMessageComposerLayout",
        "values": ["'compact'", "'multiline'"],
        "default": "'compact'"
      }
    },
    "textInput": {
      "initialText": { "type": "string", "default": "undefined" },
      "text": { "type": "string", "default": "undefined", "note": "Controlled mode — consumer owns state" },
      "placeholder": { "type": "string", "default": "'Type a message...'" },
      "enterKeyBehavior": {
        "type": "'send' | 'newline' | 'none'",
        "default": "'send'"
      },
      "maxInputHeight": { "type": "number", "default": "200" }
    },
    "richText": {
      "enableRichTextEditor": { "type": "boolean", "default": false },
      "hideRichTextFormattingOptions": { "type": "boolean", "default": false },
      "showBubbleMenuOnSelection": { "type": "boolean", "default": false }
    },
    "editReply": {
      "messageToEdit": { "type": "CometChat.TextMessage | null", "default": "null" },
      "messageToReply": { "type": "CometChat.BaseMessage | null", "default": "null" }
    },
    "attachments": {
      "attachmentOptions": { "type": "CometChatComposerAttachmentOption[]", "default": "undefined" },
      "hideAttachmentOptions": { "type": "CometChatAttachmentHideOptions", "default": "undefined" },
      "showAttachmentPreview": { "type": "boolean", "default": true },
      "maxAttachments": { "type": "number", "default": 10 },
      "allowedFileTypes": { "type": "string[]", "default": "undefined" },
      "maxFileSize": { "type": "number", "default": "undefined" }
    },
    "hideButtons": {
      "hideAttachmentButton": { "type": "boolean", "default": false },
      "hideEmojiKeyboardButton": { "type": "boolean", "default": false },
      "hideVoiceRecordingButton": { "type": "boolean", "default": false },
      "hideStickersButton": { "type": "boolean", "default": false },
      "hideAIButton": { "type": "boolean", "default": true },
      "hideLiveReaction": { "type": "boolean", "default": false },
      "hideSendButton": { "type": "boolean", "default": false },
      "hideError": { "type": "boolean", "default": false }
    },
    "mentions": {
      "textFormatters": { "type": "CometChatTextFormatter[]", "default": "undefined" },
      "disableMentions": { "type": "boolean", "default": false },
      "disableMentionAll": { "type": "boolean", "default": false },
      "mentionAllLabel": { "type": "string", "default": "'all'" },
      "mentionsUsersRequestBuilder": { "type": "CometChat.UsersRequestBuilder", "default": "undefined" },
      "mentionsGroupMembersRequestBuilder": { "type": "CometChat.GroupMembersRequestBuilder", "default": "undefined" }
    },
    "sound": {
      "disableTypingEvents": { "type": "boolean", "default": false },
      "disableSoundForMessage": { "type": "boolean", "default": false },
      "customSoundForMessage": { "type": "string", "default": "undefined" }
    },
    "misc": {
      "disableAutoFocusOnMobile": { "type": "boolean", "default": true },
      "liveReactionIcon": { "type": "string", "default": "undefined" },
      "showScrollbar": { "type": "boolean", "default": false }
    },
    "customViews": {
      "attachmentButtonIconView": "ReactNode",
      "voiceRecordingButtonIconView": "ReactNode",
      "emojiButtonIconView": "ReactNode",
      "sendButtonView": "ReactNode",
      "auxiliaryButtonView": "ReactNode",
      "headerView": "ReactNode"
    },
    "callbacks": {
      "onTextChange": "(text: string) => void",
      "onSendButtonClick": "(message: CometChat.BaseMessage, mode?: 'send' | 'edit') => void",
      "sendTextMessageOverride": "(text: string, richTextHtml?: string) => string",
      "onError": "(error: unknown) => void",
      "onClosePreview": "() => void",
      "onAttachmentAdded": "(file: File) => void",
      "onAttachmentRemoved": "(file: File) => void",
      "onMentionSelected": "(user: CometChat.User | CometChat.GroupMember) => void"
    }
  },
  "events": {
    "emitted": [
      { "name": "ui:message/sent", "payload": "{ message, status }", "description": "Message sent (inprogress → success/error)" },
      { "name": "ui:compose/edit", "payload": "{ message, status }", "description": "Message edit (inprogress → success/error/cancelled)" },
      { "name": "ui:compose/reply", "payload": "{ message, status }", "description": "Reply context set/cleared" },
      { "name": "ui:compose/recording-started", "payload": "{ composerInstanceId }", "description": "Voice recording started (stops other instances)" }
    ],
    "received": [
      { "name": "ui:compose/edit", "payload": "{ message, status: 'inprogress' }", "description": "Enters edit mode for the message" },
      { "name": "ui:compose/reply", "payload": "{ message, status: 'inprogress' }", "description": "Sets reply-to message" },
      { "name": "ui:compose/text", "payload": "{ text }", "description": "Sets the composer text programmatically" },
      { "name": "ui:compose/recording-started", "payload": "{ composerInstanceId }", "description": "Stops own recording if another instance started" }
    ]
  },
  "sdkListeners": [],
  "types": {
    "CometChatMessageComposerLayout": "'compact' | 'multiline'",
    "CometChatAttachmentHideOptions": {
      "image": "boolean | undefined",
      "video": "boolean | undefined",
      "audio": "boolean | undefined",
      "file": "boolean | undefined",
      "polls": "boolean | undefined",
      "collaborativeDocument": "boolean | undefined",
      "collaborativeWhiteboard": "boolean | undefined"
    }
  }
}

Overview

CometChatMessageComposer is a rich text input component for sending messages. It supports attachments, emoji, voice recording, mentions, rich text formatting, and reply/edit previews. Wire it alongside CometChatMessageList and CometChatMessageHeader to build a complete messaging experience.
Live Preview — interact with the default message composer.Open in Storybook ↗
The component handles:
  • Text input with placeholder and auto-resize
  • Rich text formatting (bold, italic, links, code, lists)
  • File attachments with preview thumbnails
  • Emoji keyboard
  • Voice recording
  • @mentions with user/group member search
  • Edit and reply mode with preview banners
  • Typing indicator events
  • Live reactions

Usage

Flat API

import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";

function ChatPanel({ user }: { user: CometChat.User }) {
  return (
    <CometChatMessageComposer
      user={user}
      onSendButtonClick={(message, mode) => {
        console.log(`Message ${mode}:`, message);
      }}
    />
  );
}

Compound Composition

import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";

function ChatPanel({ user }: { user: CometChat.User }) {
  return (
    <CometChatMessageComposer.Root user={user}>
      <CometChatMessageComposer.Header />
      <CometChatMessageComposer.EditPreview />
      <CometChatMessageComposer.ReplyPreview />
      <CometChatMessageComposer.Input />
      <CometChatMessageComposer.AuxiliaryButtons />
      <CometChatMessageComposer.AttachmentButton />
      <CometChatMessageComposer.EmojiButton />
      <CometChatMessageComposer.VoiceButton />
      <CometChatMessageComposer.AIButton />
      <CometChatMessageComposer.SendButton />
      <CometChatMessageComposer.Footer />
    </CometChatMessageComposer.Root>
  );
}

Full Layout Example

import { useState } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatConversations,
  CometChatMessageHeader,
  CometChatMessageList,
  CometChatMessageComposer,
} from "@cometchat/chat-uikit-react";

function ChatApp() {
  const [user, setUser] = useState<CometChat.User | undefined>();
  const [group, setGroup] = useState<CometChat.Group | undefined>();

  const handleConversationClick = (conversation: CometChat.Conversation) => {
    const entity = conversation.getConversationWith();
    if (conversation.getConversationType() === "user") {
      setUser(entity as CometChat.User);
      setGroup(undefined);
    } else {
      setGroup(entity as CometChat.Group);
      setUser(undefined);
    }
  };

  return (
    <div style={{ display: "flex", height: "100vh" }}>
      <div style={{ width: 360 }}>
        <CometChatConversations onItemClick={handleConversationClick} />
      </div>
      <div style={{ flex: 1, display: "flex", flexDirection: "column" }}>
        <CometChatMessageHeader user={user} group={group} />
        <CometChatMessageList user={user} group={group} />
        <CometChatMessageComposer user={user} group={group} />
      </div>
    </div>
  );
}

Actions and Events

Callback Props

PropSignatureFires when
onSendButtonClick(message: CometChat.BaseMessage, mode?: 'send' | 'edit') => voidMessage is sent or edited
onTextChange(text: string) => voidText content changes
onError(error: unknown) => voidAn error occurs
onClosePreview() => voidReply/edit preview is closed
onAttachmentAdded(file: File) => voidFile attachment is added
onAttachmentRemoved(file: File) => voidFile attachment is removed
onMentionSelected(user: CometChat.User | CometChat.GroupMember) => voidA mention is selected from suggestions

Events Emitted

UI events this component publishes:
EventPayloadFires when
ui:message/sent{ message, status }Message sent (inprogress → success/error)
ui:compose/edit{ message, status }Message edit (inprogress → success/error/cancelled)
ui:compose/reply{ message, status }Reply context set/cleared
ui:compose/recording-started{ composerInstanceId }Voice recording started (stops other instances)

Events Received

UI events this component subscribes to (published by other components):
EventPayloadBehavior
ui:compose/edit{ message, status: 'inprogress' }Enters edit mode for the message
ui:compose/reply{ message, status: 'inprogress' }Sets reply-to message
ui:compose/text{ text }Sets the composer text programmatically
ui:compose/recording-started{ composerInstanceId }Stops own recording if another instance started

SDK Listeners (Automatic)

The composer does not subscribe to SDK listeners directly. It relies on typing indicator events emitted via the SDK when disableTypingEvents is false.

Customization

View Props

Use view props to replace sections of the default UI while keeping the component’s behavior intact:
<CometChatMessageComposer
  user={user}
  headerView={<MyCustomHeader />}
  sendButtonView={<MyCustomSendButton />}
  attachmentButtonIconView={<PaperclipIcon />}
  emojiButtonIconView={<SmileyIcon />}
  voiceRecordingButtonIconView={<MicIcon />}
  auxiliaryButtonView={<GifButton />}
/>
SlotTypeReplaces
attachmentButtonIconViewReactNodeIcon inside the attachment button
voiceRecordingButtonIconViewReactNodeIcon inside the voice recording button
emojiButtonIconViewReactNodeIcon inside the emoji button
sendButtonViewReactNodeContent inside the send button
auxiliaryButtonViewReactNodeAdditional buttons in the actions area
headerViewReactNodeHeader area above the input

Compound Composition

For full layout control, use sub-components. Omit any sub-component to hide it:
<CometChatMessageComposer.Root user={user}>
  {/* No Header, EditPreview, or ReplyPreview — they won't render */}
  <CometChatMessageComposer.Input />
  <CometChatMessageComposer.SendButton />
</CometChatMessageComposer.Root>
Available sub-components:
Sub-componentDescriptionPropsFlat API equivalent
RootContext provider and containerAll Root props + children
InputText input areaclassName
SendButtonSend/edit buttonchildren, classNamesendButtonView (as children)
AttachmentButtonAttachment pickerhideOptions, classNameattachmentButtonIconView
EmojiButtonEmoji keyboard toggleclassNameemojiButtonIconView
VoiceButtonVoice recording toggleclassNamevoiceRecordingButtonIconView
EditPreviewEdit mode preview bannerclassName
ReplyPreviewReply mode preview bannerclassName
AuxiliaryButtonsCustom auxiliary buttonschildren, classNameauxiliaryButtonView
AIButtonAI features toggleclassName
HeaderHeader areachildren, classNameheaderView
FooterFooter areachildren, className

CSS Styling

Override design tokens on the component selector:
.cometchat-message-composer {
  --cometchat-background-color-01: #1a1a2e;
  --cometchat-text-color-primary: #ffffff;
}

.cometchat-message-composer__input-area {
  border-radius: 12px;
}

Props

All props are optional unless noted.
View slot props (headerView, sendButtonView, auxiliaryButtonView, attachmentButtonIconView, voiceRecordingButtonIconView, emojiButtonIconView) are convenience props available only on the flat API. In compound composition mode, use the corresponding sub-components directly or pass children to them.

Entity


user

User for 1:1 conversations.
TypeCometChat.User
Defaultundefined

group

Group for group conversations.
TypeCometChat.Group
Defaultundefined

parentMessageId

Parent message ID for threaded replies.
Typenumber
Defaultundefined

Layout


layout

Layout mode for the composer. compact keeps everything on one line; multiline expands the input area.
Type'compact' | 'multiline'
Default'compact'

Text Input


initialText

Initial text to pre-fill the input (uncontrolled).
Typestring
Defaultundefined

text

Controlled text value. When provided, the consumer owns the text state and must update it via onTextChange.
Typestring
Defaultundefined

placeholder

Placeholder text shown when the input is empty.
Typestring
Default'Type a message...'

enterKeyBehavior

What happens when the user presses Enter.
Type'send' | 'newline' | 'none'
Default'send'

maxInputHeight

Maximum height for the input area in pixels before it scrolls.
Typenumber
Default200

Rich Text


enableRichTextEditor

Enable rich text formatting (toolbar, keyboard shortcuts, markdown auto-conversion).
Typeboolean
Defaultfalse

hideRichTextFormattingOptions

Hide the rich text formatting toolbar (shortcuts still work).
Typeboolean
Defaultfalse

showBubbleMenuOnSelection

Show a floating bubble menu near selected text with formatting options (desktop only).
Typeboolean
Defaultfalse

Edit / Reply


messageToEdit

Message to edit (triggers edit mode).
TypeCometChat.TextMessage | null
Defaultnull

messageToReply

Message to reply to (triggers reply mode with preview).
TypeCometChat.BaseMessage | null
Defaultnull

Attachments


attachmentOptions

Custom attachment options (overrides plugin-provided ones).
TypeCometChatComposerAttachmentOption[]
Defaultundefined

hideAttachmentOptions

Hide specific attachment options in the default layout.
TypeCometChatAttachmentHideOptions
Defaultundefined
<CometChatMessageComposer
  user={user}
  hideAttachmentOptions={{ polls: true, collaborativeWhiteboard: true }}
/>

showAttachmentPreview

Whether to show attachment preview thumbnails before sending.
Typeboolean
Defaulttrue

maxAttachments

Maximum number of attachments allowed.
Typenumber
Default10

allowedFileTypes

Allowed file MIME types for attachments.
Typestring[]
Defaultundefined (all types allowed)

maxFileSize

Maximum file size in bytes.
Typenumber
Defaultundefined (no limit)

Hide Buttons


hideAttachmentButton

Hide the attachment (”+”) button entirely.
Typeboolean
Defaultfalse

hideEmojiKeyboardButton

Hide the emoji keyboard button.
Typeboolean
Defaultfalse

hideVoiceRecordingButton

Hide the voice recording button.
Typeboolean
Defaultfalse

hideStickersButton

Hide the stickers button.
Typeboolean
Defaultfalse

hideAIButton

Hide the AI button.
Typeboolean
Defaulttrue

hideLiveReaction

Hide the live reaction button.
Typeboolean
Defaultfalse

hideSendButton

Hide the send button.
Typeboolean
Defaultfalse

hideError

Hide the error state UI.
Typeboolean
Defaultfalse

Mentions


textFormatters

Text formatters pipeline for custom text processing.
TypeCometChatTextFormatter[]
Defaultundefined

disableMentions

Disable @mentions entirely.
Typeboolean
Defaultfalse

disableMentionAll

Disable the @all mention option in groups.
Typeboolean
Defaultfalse

mentionAllLabel

Label for the @all mention option.
Typestring
Default'all'

mentionsUsersRequestBuilder

Custom request builder for mention user search.
TypeCometChat.UsersRequestBuilder
Defaultundefined

mentionsGroupMembersRequestBuilder

Custom request builder for mention group member search.
TypeCometChat.GroupMembersRequestBuilder
Defaultundefined

Sound


disableTypingEvents

Disable typing indicator events.
Typeboolean
Defaultfalse

disableSoundForMessage

Disable sound on message send.
Typeboolean
Defaultfalse

customSoundForMessage

Custom sound URL for message send.
Typestring
Defaultundefined

Misc


disableAutoFocusOnMobile

Disable auto-focus on mobile devices to prevent the keyboard from automatically opening on load.
Typeboolean
Defaulttrue

liveReactionIcon

Custom icon URL for the live reaction button.
Typestring
Defaultundefined

showScrollbar

Show the native scrollbar on the input area.
Typeboolean
Defaultfalse

Custom Views


attachmentButtonIconView

Custom ReactNode to replace the content inside the attachment button (keeps action wired).
TypeReactNode
Defaultundefined

voiceRecordingButtonIconView

Custom ReactNode to replace the content inside the voice recording button (keeps action wired).
TypeReactNode
Defaultundefined

emojiButtonIconView

Custom ReactNode to replace the content inside the emoji button (keeps action wired).
TypeReactNode
Defaultundefined

sendButtonView

Custom ReactNode to replace the content inside the send button (keeps send/edit action wired).
TypeReactNode
Defaultundefined

auxiliaryButtonView

Custom ReactNode for additional buttons rendered in the actions area before the send button.
TypeReactNode
Defaultundefined

headerView

Custom ReactNode for the header area above the input (replaces edit/reply preview + validation).
TypeReactNode
Defaultundefined

Callbacks


onTextChange

Called when text changes.
Type(text: string) => void
Defaultundefined

onSendButtonClick

Called when a message is sent or edited.
Type(message: CometChat.BaseMessage, mode?: 'send' | 'edit') => void
Defaultundefined

sendTextMessageOverride

Override the internal SDK sendTextMessage call for optimistic updates. When provided, called instead of CometChat.sendMessage().
Type(text: string, richTextHtml?: string) => string
Defaultundefined

onError

Called when an error occurs.
Type(error: unknown) => void
Defaultundefined

onClosePreview

Called when reply/edit preview is closed.
Type() => void
Defaultundefined

onAttachmentAdded

Called when a file attachment is added.
Type(file: File) => void
Defaultundefined

onAttachmentRemoved

Called when a file attachment is removed.
Type(file: File) => void
Defaultundefined

onMentionSelected

Called when a mention is selected from the suggestions list.
Type(user: CometChat.User | CometChat.GroupMember) => void
Defaultundefined

CSS Selectors

TargetSelector
Root container.cometchat-message-composer
Body wrapper.cometchat-message-composer__body
Input area.cometchat-message-composer__input-area
Actions bar.cometchat-message-composer__actions
Attachment button.cometchat-message-composer__attachment-button-wrapper
Emoji button.cometchat-message-composer__emoji-button-wrapper
Voice button.cometchat-message-composer__voice-button-wrapper
Send button.cometchat-message-composer__send-button-wrapper
Sticker button.cometchat-message-composer__sticker-button-wrapper
AI button.cometchat-message-composer__ai-button-wrapper

Next Steps

Message List

Display messages for the selected conversation

Thread Header

Show threaded replies for a parent message

Theming

Customize colors, fonts, and spacing