Skip to main content
{
  "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 for composing and sending text, media, attachments, mentions, voice notes, and custom messages.",
  "cssRootClass": ".cometchat-message-composer",
  "primaryOutput": {
    "prop": "onSendButtonClick",
    "type": "(message: CometChat.BaseMessage, previewMessageMode?: PreviewMessageMode) => void"
  },
  "props": {
    "data": {
      "user": { "type": "CometChat.User", "default": "undefined" },
      "group": { "type": "CometChat.Group", "default": "undefined" },
      "parentMessageId": { "type": "number", "default": "undefined" },
      "initialComposerText": { "type": "string", "default": "\"\"" },
      "placeholderText": { "type": "string", "default": "\"\"" }
    },
    "callbacks": {
      "onSendButtonClick": "(message: CometChat.BaseMessage, previewMessageMode?: PreviewMessageMode) => void",
      "onTextChange": "(text: string) => void",
      "onError": "((error: CometChat.CometChatException) => void) | null"
    },
    "visibility": {
      "hideImageAttachmentOption": { "type": "boolean", "default": false },
      "hideVideoAttachmentOption": { "type": "boolean", "default": false },
      "hideAudioAttachmentOption": { "type": "boolean", "default": false },
      "hideFileAttachmentOption": { "type": "boolean", "default": false },
      "hidePollsOption": { "type": "boolean", "default": false },
      "hideCollaborativeDocumentOption": { "type": "boolean", "default": false },
      "hideCollaborativeWhiteboardOption": { "type": "boolean", "default": false },
      "hideAttachmentButton": { "type": "boolean", "default": false },
      "hideVoiceRecordingButton": { "type": "boolean", "default": false },
      "hideEmojiKeyboardButton": { "type": "boolean", "default": false },
      "hideStickersButton": { "type": "boolean", "default": false },
      "hideSendButton": { "type": "boolean", "default": false },
      "showScrollbar": { "type": "boolean", "default": false }
    },
    "behavior": {
      "disableTypingEvents": { "type": "boolean", "default": false },
      "disableMentions": { "type": "boolean", "default": false },
      "disableMentionAll": { "type": "boolean", "default": false },
      "mentionAllLabel": { "type": "string", "default": "\"all\"" },
      "enterKeyBehavior": { "type": "EnterKeyBehavior", "default": "EnterKeyBehavior.SendMessage" },
      "disableSoundForMessage": { "type": "boolean", "default": false },
      "customSoundForMessage": { "type": "string", "default": "undefined" }
    },
    "mentions": {
      "mentionsUsersRequestBuilder": "CometChat.UsersRequestBuilder",
      "mentionsGroupMembersRequestBuilder": "CometChat.GroupMembersRequestBuilder"
    },
    "viewSlots": {
      "attachmentOptions": "CometChatMessageComposerAction[]",
      "auxiliaryButtonView": "JSX.Element",
      "sendButtonView": "JSX.Element",
      "headerView": "JSX.Element"
    },
    "formatting": {
      "textFormatters": { "type": "CometChatTextFormatter[]", "default": "default formatters" }
    }
  },
  "events": [
    { "name": "CometChatMessageEvents.ccMessageSent", "payload": "IMessages" },
    { "name": "CometChatMessageEvents.ccMessageEdited", "payload": "IMessages" },
    { "name": "CometChatMessageEvents.ccReplyToMessage", "payload": "IMessages" }
  ],
  "sdkListeners": [],
  "types": {
    "EnterKeyBehavior": { "SendMessage": "sendMessage", "NewLine": "newLine", "None": "none" },
    "PreviewMessageMode": { "edit": 0, "none": 1 }
  }
}

Where It Fits

CometChatMessageComposer provides a rich text input with attachment, emoji, voice recording, sticker, and send controls. Wire it alongside CometChatMessageHeader and CometChatMessageList to build a standard chat view.
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatMessageHeader,
  CometChatMessageList,
  CometChatMessageComposer,
} from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

function ChatView() {
  const [chatUser, setChatUser] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("uid").then((user) => setChatUser(user));
  }, []);

  return chatUser ? (
    <div style={{ height: "100vh", display: "flex", flexDirection: "column" }}>
      <CometChatMessageHeader user={chatUser} />
      <CometChatMessageList user={chatUser} />
      <CometChatMessageComposer user={chatUser} />
    </div>
  ) : null;
}

Minimal Render

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

function MessageComposerDemo() {
  const [chatUser, setChatUser] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("uid").then((user) => setChatUser(user));
  }, []);

  return chatUser ? <CometChatMessageComposer user={chatUser} /> : null;
}

export default MessageComposerDemo;
Root CSS class: .cometchat-message-composer

Actions and Events

Callback Props

onSendButtonClick

Fires when the send button is clicked. Overrides the default send behavior.
import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";
import { CometChat } from "@cometchat/chat-sdk-javascript";

function ComposerWithCustomSend() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      onSendButtonClick={(message: CometChat.BaseMessage) => {
        console.log("Custom send:", message);
      }}
    />
  );
}

onTextChange

Fires as the user types in the composer input.
import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";

function ComposerWithTextTracking() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      onTextChange={(text: string) => {
        console.log("Text changed:", text);
      }}
    />
  );
}

onError

Fires on internal errors.
import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";
import { CometChat } from "@cometchat/chat-sdk-javascript";

function ComposerWithError() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      onError={(error: CometChat.CometChatException) => {
        console.error("Composer error:", error);
      }}
    />
  );
}

Global UI Events

EventFires whenPayload
CometChatMessageEvents.ccMessageSentA message is sentIMessages
CometChatMessageEvents.ccMessageEditedA message is editedIMessages
CometChatMessageEvents.ccReplyToMessageUser replies to a messageIMessages
import { useEffect } from "react";
import { CometChatMessageEvents } from "@cometchat/chat-uikit-react";

function useComposerEvents() {
  useEffect(() => {
    const sentSub = CometChatMessageEvents.ccMessageSent.subscribe(
      (data) => console.log("Sent:", data)
    );
    const editedSub = CometChatMessageEvents.ccMessageEdited.subscribe(
      (data) => console.log("Edited:", data)
    );

    return () => {
      sentSub?.unsubscribe();
      editedSub?.unsubscribe();
    };
  }, []);
}

SDK Events (Real-Time, Automatic)

The component internally handles typing indicators and message sending. No manual SDK listener attachment needed.

Custom View Slots

SlotTypeReplaces
attachmentOptionsCometChatMessageComposerAction[]Default attachment options list
auxiliaryButtonViewJSX.ElementSticker and AI button area
sendButtonViewJSX.ElementSend button
headerViewJSX.ElementArea above the composer input

attachmentOptions

Override the default attachment options.
import {
  CometChatMessageComposer,
  CometChatMessageComposerAction,
} from "@cometchat/chat-uikit-react";

function ComposerCustomAttachments() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      attachmentOptions={[
        new CometChatMessageComposerAction({
          id: "custom1",
          title: "Custom Option 1",
          iconURL: "icon-url",
        }),
        new CometChatMessageComposerAction({
          id: "custom2",
          title: "Custom Option 2",
          iconURL: "icon-url",
        }),
      ]}
    />
  );
}

auxiliaryButtonView

Replace the sticker and AI button area.
import {
  CometChatMessageComposer,
  CometChatButton,
} from "@cometchat/chat-uikit-react";

function ComposerCustomAuxiliary() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      auxiliaryButtonView={
        <CometChatButton iconURL="icon-url" onClick={() => {}} />
      }
    />
  );
}

sendButtonView

Replace the send button.
import {
  CometChatMessageComposer,
  CometChatButton,
} from "@cometchat/chat-uikit-react";

function ComposerCustomSend() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      sendButtonView={
        <CometChatButton iconURL="icon-url" onClick={() => {}} />
      }
    />
  );
}

headerView

Custom view above the composer input.
import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";

function ComposerWithHeader() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      headerView={
        <div className="message-composer__header-view">
          <div className="message-composer__header-view-icon" />
          <div className="message-composer__header-view-text">
            User has paused their notifications
          </div>
        </div>
      }
    />
  );
}

Common Patterns

Thread composer

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

function ThreadComposer() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      parentMessageId={parentMessage.getId()}
    />
  );
}

Minimal composer — text only

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

function MinimalComposer() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      hideAttachmentButton={true}
      hideVoiceRecordingButton={true}
      hideEmojiKeyboardButton={true}
      hideStickersButton={true}
    />
  );
}

Enter key adds new line

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

function NewLineComposer() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      enterKeyBehavior={EnterKeyBehavior.NewLine}
    />
  );
}

Pre-filled text

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

function PrefilledComposer() {
  return (
    <CometChatMessageComposer
      user={chatUser}
      initialComposerText="Hello! "
      placeholderText="Type a message..."
    />
  );
}

CSS Architecture

The component uses CSS custom properties (design tokens) defined in @cometchat/chat-uikit-react/css-variables.css. The cascade:
  1. Global tokens set on the .cometchat root wrapper.
  2. Component CSS (.cometchat-message-composer) consumes these tokens via var().
  3. Overrides target .cometchat-message-composer descendant selectors.

Key Selectors

TargetSelector
Root.cometchat-message-composer
Send button.cometchat-message-composer__send-button
Send button active.cometchat-message-composer__send-button-active
Sticker button popover.cometchat-message-composer__auxilary-button-view-sticker-button .cometchat-popover__content
Emoji keyboard popover.cometchat-message-composer__emoji-keyboard-button .cometchat-popover__content
Attachment popover.cometchat-message-composer__secondary-button-view-attachment-button .cometchat-popover__content
Voice recording popover.cometchat-message-composer__voice-recording-button .cometchat-popover__content
Header area.cometchat-message-composer__header

Customization Matrix

What to changeWhereProperty/APIExample
Override send behaviorComponent propsonSendButtonClickonSendButtonClick={(msg) => customSend(msg)}
Track text inputComponent propsonTextChangeonTextChange={(text) => track(text)}
Toggle visibilityComponent propshide<Feature> boolean propshideAttachmentButton={true}
Custom attachmentsComponent propsattachmentOptionsattachmentOptions={[new CometChatMessageComposerAction(...)]}
Replace UI sectionsComponent propsView slot propssendButtonView={<div>...</div>}
Change Enter key behaviorComponent propsenterKeyBehaviorenterKeyBehavior={EnterKeyBehavior.NewLine}
Change colors, fonts, spacingGlobal CSSTarget .cometchat-message-composer class.cometchat-message-composer__send-button { background: blue; }

Accessibility

The text input is auto-focused and supports standard keyboard shortcuts. The send button activates on Enter (configurable via enterKeyBehavior). Attachment, emoji, sticker, and voice recording buttons are keyboard-focusable and activate on Enter/Space. The mention suggestions list is keyboard-navigable with arrow keys.

Props

All props are optional. Sorted alphabetically.

attachmentOptions

Custom attachment options list.
TypeCometChatMessageComposerAction[]
Defaultundefined

auxiliaryButtonView

Custom JSX replacing the sticker and AI button area.
TypeJSX.Element
DefaultBuilt-in sticker/AI buttons

customSoundForMessage

URL to a custom audio file for outgoing message notifications.
Typestring
Defaultundefined

disableMentionAll

Controls whether group mentions like @all appear in suggestions.
Typeboolean
Defaultfalse

disableMentions

Disables the mentions functionality.
Typeboolean
Defaultfalse

disableSoundForMessage

Disables sound for outgoing messages.
Typeboolean
Defaultfalse

disableTypingEvents

Disables the typing indicator for this composer.
Typeboolean
Defaultfalse

enterKeyBehavior

Determines Enter key behavior.
TypeEnterKeyBehavior
DefaultEnterKeyBehavior.SendMessage
enum EnterKeyBehavior {
  SendMessage = "sendMessage",
  NewLine = "newLine",
  None = "none",
}

group

The recipient group for the composer.
TypeCometChat.Group
Defaultundefined

headerView

Custom component displayed above the composer input.
TypeJSX.Element
Defaultundefined

hideAttachmentButton

Hides the entire attachment button.
Typeboolean
Defaultfalse

hideAudioAttachmentOption

Hides the audio attachment option.
Typeboolean
Defaultfalse

hideCollaborativeDocumentOption

Hides the collaborative document option.
Typeboolean
Defaultfalse

hideCollaborativeWhiteboardOption

Hides the collaborative whiteboard option.
Typeboolean
Defaultfalse

hideEmojiKeyboardButton

Hides the emoji keyboard button.
Typeboolean
Defaultfalse

hideFileAttachmentOption

Hides the file attachment option.
Typeboolean
Defaultfalse

hideImageAttachmentOption

Hides the image attachment option.
Typeboolean
Defaultfalse

hidePollsOption

Hides the polls option.
Typeboolean
Defaultfalse

hideSendButton

Hides the send button.
Typeboolean
Defaultfalse

hideStickersButton

Hides the stickers button.
Typeboolean
Defaultfalse

hideVideoAttachmentOption

Hides the video attachment option.
Typeboolean
Defaultfalse

hideVoiceRecordingButton

Hides the voice recording button.
Typeboolean
Defaultfalse

initialComposerText

Pre-fills the text input when the component mounts.
Typestring
Default""

mentionAllLabel

Custom alias label for group mentions.
Typestring
Default"all"

mentionsGroupMembersRequestBuilder

Custom builder to control how mentioned group members are fetched.
TypeCometChat.GroupMembersRequestBuilder
Defaultundefined

mentionsUsersRequestBuilder

Custom builder to control how mentioned users are fetched.
TypeCometChat.UsersRequestBuilder
Defaultundefined

onError

Callback fired when the component encounters an error.
Type((error: CometChat.CometChatException) => void) | null
Defaultundefined

onSendButtonClick

Callback fired when the send button is clicked. Overrides default send behavior.
Type(message: CometChat.BaseMessage, previewMessageMode?: PreviewMessageMode) => void
Defaultundefined

onTextChange

Callback fired as the user types.
Type(text: string) => void
Defaultundefined

parentMessageId

Targets a thread; messages sent as replies to this parent.
Typenumber
Defaultundefined

placeholderText

Placeholder text displayed in the message input field when empty.
Typestring
Default""

sendButtonView

Custom JSX replacing the send button.
TypeJSX.Element
DefaultBuilt-in send button

showScrollbar

Shows the scrollbar in the composer input.
Typeboolean
Defaultfalse

textFormatters

Custom text formatters for the composer input.
TypeCometChatTextFormatter[]
DefaultDefault formatters from data source
See CometChatMentionsFormatter.

user

The recipient user for the composer.
TypeCometChat.User
Defaultundefined

Events

EventPayloadFires when
CometChatMessageEvents.ccMessageSentIMessagesMessage sent
CometChatMessageEvents.ccMessageEditedIMessagesMessage edited
CometChatMessageEvents.ccReplyToMessageIMessagesUser replies to message

CSS Selectors

TargetSelector
Root.cometchat-message-composer
Send button.cometchat-message-composer__send-button
Send button active.cometchat-message-composer__send-button-active
Sticker popover.cometchat-message-composer__auxilary-button-view-sticker-button .cometchat-popover__content
Emoji keyboard popover.cometchat-message-composer__emoji-keyboard-button .cometchat-popover__content
Attachment popover.cometchat-message-composer__secondary-button-view-attachment-button .cometchat-popover__content
Voice recording popover.cometchat-message-composer__voice-recording-button .cometchat-popover__content
Header area.cometchat-message-composer__header