Skip to main content
composer.replaceSelection() requires @cometchat/chat-uikit-react-native 5.5.1 or later. It does not exist on the ComposerInputHandle in 5.5.0. Every other handle method, and the rest of this page, works on either version.

Where It Fits

CometChatCompactMessageComposer is a Component that provides a compact, streamlined message input with optional rich text formatting capabilities. Its formatting toolbar supports bold, italic, underline, strikethrough, links, lists, blockquotes, inline code, and code blocks, along with auto-expanding input, attachments, mentions, voice recording, and message editing. This is a compact variant of CometChatMessageComposer. It shares the same props API but adds rich text formatting controls, auto-expanding input configuration, and additional callbacks. Wire it alongside CometChatMessageHeader and CometChatMessageList to build a standard chat view.

Minimal Render


Actions and Events

Callback Props

onSendButtonPress

Fires when the send message button is clicked. Overrides the default send behavior.

onError

Fires on internal errors (network failure, auth issue, SDK exception).

onChangeText

Fires as the user types in the composer input.

onMentionLimitReached

Fires when the maximum mention limit per message is reached.

Global UI Events

CometChatUIEventHandler emits events subscribable from anywhere in the application. Add listeners and remove them on cleanup. When to use: sync external UI with message state changes. For example, update a notification badge when messages are sent, or trigger analytics when a message is edited.
In React 18 StrictMode, useEffect runs twice on mount in development. The component handles listener cleanup internally, but any additional listeners added alongside the component need cleanup in the useEffect return function to avoid duplicate event handling.

Rich Text Formatting

The CompactMessageComposer includes a built-in rich text editor. Rich text is enabled by default via enableRichTextEditor={true}.

Formatting Toolbar

The toolbar provides the following formatting tools:

Toolbar Visibility Modes

The toolbar supports multiple display modes controlled via props:

Text Selection Menu Items

On React Native, the showTextSelectionMenuItems prop controls whether Bold, Italic, Underline, and Strikethrough options appear in the native text selection context menu (long-press popup). This is enabled by default.

Enter Key Behavior (Android Only)

The enterKeyBehavior prop controls what happens when the Enter key is pressed on Android. On iOS, Enter always inserts a new line.

Toolbar Configuration Examples


Auto-Expanding Input

The CompactMessageComposer input auto-expands as the user types, up to a configurable maximum.

Custom View Slots

Each slot replaces a section of the default UI. Slots that accept parameters receive the relevant data for customization.

textFormatters

Custom text formatters for the composer input. To configure the existing Mentions look and feel check out CometChatMentionsFormatter.

attachmentOptions

Override the default attachment options with custom actions.

addAttachmentOptions

Extends the default attachment options with additional actions.

AuxiliaryButtonView

Replace the sticker button area with a custom view.
The CompactMessageComposer Component utilizes the AuxiliaryButton to provide sticker functionality. Overriding the AuxiliaryButton will replace the sticker functionality.

SendButtonView

Replace the send button with a custom view.

ToolbarTrailingButtonsView

Render your own buttons at the trailing end of the rich-text formatting toolbar, after the built-in buttons and a divider. This is the place for a formatting control the toolbar does not have — for example, a color button that colors the selected text. Besides user, group and composerId, the render function receives a composer handle (ComposerInputHandle) for reading and changing the input — without it a toolbar button could not act on the text.
The slot lives inside the toolbar, so it only renders while the toolbar is visible — enableRichTextEditor true and hideRichTextFormattingOptions false, which are the defaults. It does not appear in the native text selection menu. For a complete walkthrough with a swatch picker, see the Text Color guide.
Render your controls inline in the toolbar rather than in a Modal. A modal takes focus from the input, which collapses the selection before your command runs.
The composer handle: Only "color" is sent with the message, as <color=#rrggbb>…</color>, and the UI Kit renders it in the bubble automatically. "backgroundColor" styles the composer only and is dropped on send.

HeaderView

Custom view above the composer input.

FooterView

Custom view below the composer input.

Styling

Using the style prop you can customize the look and feel of the component in your app. These parameters typically control elements such as the color, size, shape, and fonts used within the component.

Visibility Props


Configuration

SingleLineMessageComposerConfiguration can be used to pass configuration when embedding the CompactMessageComposer inside other components:

Next Steps

Message Composer

Full-featured multi-line message composer component

Message List

Display the list of messages in a conversation

Mentions Formatter

Implement @mentions in your chat application

Component Styling

Customize the appearance of UI Kit components