Skip to content
+

Chat - Composer

Compose and send chat messages with attachments, toolbar actions, and helper text.

The composer is the input region at the bottom of the chat surface. ChatComposer provides Material UI styling—border, padding, and theme tokens are applied automatically.

Import

import {
  ChatComposer,
  ChatComposerLabel,
  ChatComposerTextArea,
  ChatComposerSendButton,
  ChatComposerAttachButton,
  ChatComposerToolbar,
  ChatComposerHelperText,
} from '@mui/x-chat';

Component anatomy

Inside ChatBox, the composer renders the following structure:

ChatComposer                  ← <form> element, border-top divider
  ChatComposerLabel           ← optional <label> for accessibility
  ChatComposerTextArea        ← auto-resizing textarea
  ChatComposerToolbar         ← button row
    ChatComposerAttachButton  ← file attach trigger
    ChatComposerSendButton    ← submit button (disabled when empty with no attachments/streaming)
  ChatComposerHelperText      ← disclaimer or character count

Text area

ChatComposerTextArea is an auto-resizing <textarea> that grows with content. It submits on Enter and inserts a newline on Shift+Enter.

Customizing the placeholder

Customize the placeholder through slotProps:

Material UI chat

Styled with your active MUI theme

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

IME composition

The composer handles IME (Input Method Editor) composition for CJK languages. While the user is composing characters (for example, selecting Kanji), pressing Enter confirms the character selection instead of submitting the message. Submission is blocked until composition ends.

Send button

The send button is automatically disabled when:

  • The text area is empty and there are no queued attachments.
  • A response is currently streaming.
  • The composer is explicitly disabled.

Attach button

The attach button opens the browser file picker. Selected files are queued as draft attachments and previewed in the composer area.

Set features={{ attachments: false }} to hide the attach button:

Material UI chat

Styled with your active MUI theme

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

Helper text

A helper text line appears below the composer. Use it for legal disclaimers, character counts, or contextual hints.

{
  /* Hide the helper text */
}
<ChatBox adapter={adapter} features={{ helperText: false }} />;

Controlling the composer value

Control the composer value externally through ChatProvider, or through the equivalent ChatBox props that forward to it. The demo below mirrors the current composer value above the chat surface:

Composer value: (empty)

Material UI chat

Styled with your active MUI theme

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

Accessing composer state with a hook

For deeper control, the useChatComposer() hook provides direct access to the composer state:

import { useChatComposer } from '@mui/x-chat/headless';

function ComposerInfo() {
  const composer = useChatComposer();
  return (
    <div>
      <p>Current value: {composer.value}.</p>
      <p>Attachments: {composer.attachments.length}.</p>
      <p>Submitting: {composer.isSubmitting ? 'Yes' : 'No'}.</p>
      <button onClick={() => composer.clear()}>Clear</button>
    </div>
  );
}

The hook returns:

Property Type Description
value string Current text value
setValue (value: string) => void Update the text value
attachments ChatDraftAttachment[] Queued file attachments
addAttachment (file: File) => void Add a file to the draft
removeAttachment (localId: string) => void Remove a queued file
clear () => void Reset value and attachments
submit () => Promise<void> Submit the current draft
isSubmitting boolean Whether a send is in progress

ChatDraftAttachment

The attachment type used by the composer:

Property Type Description
localId string Unique identifier for this draft attachment
file File The browser File object
previewUrl string | undefined Object URL for image previews (auto-created)
status 'queued' | 'uploading' | 'uploaded' | 'error' Upload lifecycle status
progress number | undefined Upload progress (0–100)

Compact composer variants

The demo below shows five design ideas for the compact composer variant—click into the text area to see the focus state.

1 — Top separator

Only a top border divider. Focus colors it primary.

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

2 — Floating pill

Margin + pill-shaped radius. Focus adds primary ring.

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

3 — Elevated card

No border, elevation shadow. Focus deepens shadow.

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

4 — Borderless minimal

Top separator, transparent bg. Focus tints background.

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

5 — Inset outlined

Margin + border + radius like default variant.

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

Disabling the composer

Pass disabled to prevent all interaction. When disabled, the text area is read-only and the send button is inert. The owner state exposes disabled so custom styles can react to the state.

Material UI chat

Styled with your active MUI theme

MUI Assistant
MUI Assistant

Hello! I am styled using your active Material UI theme. Try sending a message.

You
You

Great — the bubble colors come from palette.primary and the typography from the theme.

Localization

The composer uses these locale text keys (customizable via localeText on ChatBox or ChatRoot):

Key Default Used by
composerInputPlaceholder "Type a message" TextArea placeholder
composerInputAriaLabel "Message" TextArea aria-label, Label fallback
composerSendButtonLabel "Send message" SendButton aria-label
composerAttachButtonLabel "Add attachment" AttachButton aria-label

Slots

The following slots are available for customization through ChatBox:

Slot Component Description
composer ChatComposer The <form> container
input ChatComposerTextArea The auto-resizing textarea
send ChatComposerSendButton Submit button
attach ChatComposerAttachButton File attach trigger
toolbar ChatComposerToolbar Button row below the textarea
helperText ChatComposerHelperText Disclaimer or hint text

API

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.