Skip to contentSkip to content

ChatBox API

API reference docs for the React ChatBox component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import { ChatBox } from '@mui/x-chat/ChatBox';
// or
import { ChatBox } from '@mui/x-chat';

Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

currentUser{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: object, role?: 'assistant'
| 'system'
| 'user' }
-

The local user sending messages. If omitted, derived from members by finding the entry with role === 'user'. Also used to enrich message authors when a rendered message resolves to currentUser.id.

density'comfortable'
| 'compact'
| 'standard'
'standard'

The vertical spacing density of chat messages. - 'compact' – Reduced vertical spacing between messages. - 'standard' – Default spacing. - 'comfortable' – Increased vertical spacing between messages.

features{ attachments?: { acceptedMimeTypes?: Array<string>, maxFileCount?: number, maxFileSize?: number, onAttachmentReject?: func }
| bool, autoScroll?: { buffer?: number }
| bool, conversationHeader?: bool, conversationList?: bool, dateDivider?: bool, helperText?: bool, scrollToBottom?: bool, streamingIndicator?: 'auto'
| bool, suggestions?: bool, typingSignal?: bool, unreadMarker?: bool }
-

Feature flags to enable or disable built-in ChatBox behaviours.

getMessageAuthorAvatarUrlfunc(message) => message.author?.avatarUrl

Used to determine the avatar URL for a given message author. Falls back to message.author?.avatarUrl, then to the matched member's avatarUrl.

getMessageAuthorDisplayNamefunc(message) => message.author?.displayName

Used to determine the display name for a given message author. Falls back to message.author?.displayName, then to the matched member's displayName.

getMessageAuthorIdfunc(message) => message.author?.id

Used to determine the author id for a given message. The resolved id is used to match message authors against currentUser, members, and active conversation participants.

initialActiveConversationIdstring-

The initial active conversation ID when uncontrolled. Ignored after initialization and when activeConversationId is provided.

initialComposerValuestring-

The initial composer value when uncontrolled. Ignored after initialization and when composerValue is provided.

initialConversationsArray<{ avatarUrl?: string, id: string, lastMessageAt?: string, metadata?: object, participants?: Array<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: object, role?: 'assistant'
| 'system'
| 'user' }>, readState?: 'read'
| 'unread', subtitle?: string, title?: string, unreadCount?: number }>
-

The initial conversations when uncontrolled. Ignored after initialization and when conversations is provided.

initialMessagesArray<{ author?: { avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: object, role?: 'assistant'
| 'system'
| 'user' }, conversationId?: string, createdAt?: string, editedAt?: string, id: string, metadata?: object, parts: Array<{ data: any, id?: string, transient?: bool, type: object }
| { filename?: string, mediaType: string, type: 'file', url: string }
| { sourceId: string, text?: string, title?: string, type: 'source-document' }
| { sourceId: string, title?: string, type: 'source-url', url: string }
| { state?: 'done'
| 'streaming', text: string, type: 'reasoning' }
| { state?: 'done'
| 'streaming', text: string, type: 'text' }
| { toolInvocation: { approval?: object, approvalId?: string, callProviderMetadata?: object, errorText?: string, input?: any, output?: any, preliminary?: bool, providerExecuted?: bool, state: 'approval-requested'
| 'approval-responded'
| 'input-available'
| 'input-streaming'
| 'output-available'
| 'output-denied'
| 'output-error', title?: string, toolCallId: string, toolName: string }, type: 'dynamic-tool' }
| { toolInvocation: { approval?: object, approvalId?: string, callProviderMetadata?: object, errorText?: string, input?: any, output?: any, preliminary?: bool, providerExecuted?: bool, state: 'approval-requested'
| 'approval-responded'
| 'input-available'
| 'input-streaming'
| 'output-available'
| 'output-denied'
| 'output-error', title?: string, toolCallId: string, toolName: string }, type: 'tool' }
| { type: 'step-start' }>, role: 'assistant'
| 'system'
| 'user', status?: 'cancelled'
| 'error'
| 'pending'
| 'read'
| 'sending'
| 'sent'
| 'streaming', updatedAt?: string }>
-

The initial messages when uncontrolled. Ignored after initialization and when messages is provided.

layoutMode'overlay'
| 'split'
| 'standard'
-

Forces the responsive layout mode instead of deriving it from the container width. When omitted, ChatBox chooses the mode automatically using layoutModeBreakpoints.

layoutModeBreakpoints{ overlay?: number, split?: number }-

Container-width breakpoints used when layoutMode is not provided.

membersArray<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: object, role?: 'assistant'
| 'system'
| 'user' }>
-

Known chat participants. Used to derive the local user / assistant user when explicit props are omitted, and to enrich message authors by resolved author id at render time.

roleDisplayNames{ assistant?: string, system?: string, user?: string }-

Locale-driven fallback labels for messages without explicit author information.

slotPropsobject-

Props forwarded to each slot. Mirrors the flat keys of slots.

slotsobject-

The components used for each slot inside the ChatBox. Keys are flat and prefixed by area:
- Layout — root, layout, conversationsPane, threadPane. - Conversation — conversationRoot, conversationList, conversationHeader, conversationHeaderInfo, conversationTitle, conversationSubtitle, conversationHeaderActions. - Message list — messageList, messageGroup, dateDivider, unreadMarker, streamingIndicator. The divider slots render only when the matching features.dateDivider / features.unreadMarker flag is enabled; the streaming indicator renders by default (features.streamingIndicator: 'auto') and accepts null to hide it. - Message — messageRoot, messageAvatar, messageContent, messageMeta, messageInlineMeta, messageError, messageActions, messageAuthorName. Pass null to a presentational slot (messageAvatar, messageMeta, messageInlineMeta, messageActions, messageAuthorName) to hide it and collapse the surrounding layout. - Composer — composerRoot, composerInput, composerSendButton, composerAttachButton, composerAttachmentList, composerToolbar, composerHelperText. Pass null to composerSendButton / composerAttachButton to hide the button. - Widgets — typingIndicator, scrollToBottom, suggestions, emptyState.
*Root slots (conversationRoot, messageRoot, composerRoot) are wrapper-only: they swap the styled element while the default children still render inside.

See Slots API below for more details.

storeClassfuncChatStore

The store class to use for this provider.

streamFlushIntervalnumber16

Flush interval in milliseconds for batching rapid streaming deltas before applying them to the store.

suggestionsArray<{ label?: string, value: string }
| string>
-

Prompt suggestions displayed in the empty state. Clicking a suggestion pre-fills the composer.

suggestionsAutoSubmitboolfalse

Whether clicking a suggestion automatically submits the message.

variant'compact'
| 'default'
'default'

The visual layout variant of the chat. - 'default' – Standard layout with avatars, individual timestamps, and full spacing. - 'compact' – Messenger-style layout: no avatars, author + timestamp in group header, tighter spacing.

The component cannot hold a ref.

Slots

Slot nameClass nameDefault componentDescription
root.MuiChatBox-rootThe outermost ChatBox container element.
layout.MuiChatBox-layoutWrapper that arranges the conversations pane and the thread pane.
conversationsPane.MuiChatBox-conversationsPaneContainer for the conversation-list sidebar (or drawer on narrow widths).
threadPane.MuiChatBox-threadPaneContainer for the active thread — the message list plus the composer.
conversationRootStyled root of <ChatConversation> (wrapper-only); the default header, message list and composer continue to render inside it.
conversationListThe conversation-list sidebar component.
conversationHeaderThe header bar rendered above the message list.
conversationHeaderInfoThe title + subtitle group inside the header.
conversationTitleThe conversation title element.
conversationSubtitleThe conversation subtitle element (participants, status, etc.).
conversationHeaderActionsThe actions area on the trailing side of the header.
messageListStyled scrollable root element of <ChatMessageList> (wrapper-only). The default message rows render inside it, so a plain element such as 'section' wraps the list rather than replacing it.
messageGroupThe per-author group wrapper around consecutive messages.
dateDividerThe date separator rendered between message groups. Only rendered when features.dateDivider is enabled. Pass null to hide it.
unreadMarkerThe "new messages" marker. Only rendered when features.unreadMarker is enabled. Pass null to hide it.
streamingIndicatorThe animated dots shown while an assistant response is in flight: as a trailing row while waiting for the response to start, then inside the assistant bubble while it streams. Controlled by features.streamingIndicator ('auto' by default). Pass null to hide it.
messageRootStyled root of <ChatMessage> (wrapper-only); the default avatar/content/meta tree still renders inside it.
messageAvatarAvatar component. Pass null to hide the avatar entirely and drop the reserved avatar grid track.
messageContentThe message bubble component.
messageMetaExternal meta (compact variant). Pass null to hide.
messageInlineMetaInline meta rendered inside the bubble (default variant). Pass null to hide.
messageErrorError card shown under the bubble when the message status is error. Pass null to hide the error surface entirely (no component is mounted).
messageActionsActions row component (receives { messageId }). Pass null to hide actions entirely; omit to render only the declarative extraActions from slotProps.messageActions if provided.
messageAuthorNameAuthor name label rendered by the group wrapper (default variant: above the bubble; compact variant: inside the message grid). Pass null to hide.
composerRootStyled root of <ChatComposer> (wrapper-only); the default attach/input/send/ toolbar render inside it.
composerInputThe auto-resizing text input.
composerSendButtonSend button. Pass null to hide it; the form still submits on Enter.
composerAttachButtonAttach button. Pass null to hide just the button while keeping the rest of the attachment pipeline (drag/drop, paste). Use features.attachments: false to disable attachments entirely.
composerAttachmentListThe pending-attachment preview list.
composerToolbarThe composer toolbar (button row).
composerHelperTextThe helper / disclaimer text below the input.
typingIndicatorThe animated typing indicator shown while the assistant responds.
scrollToBottomThe floating scroll-to-bottom button.
suggestionsThe prompt-suggestion chips.
emptyStateCustom content rendered when the thread has no messages.

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.