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.
| Name | Type | Default | Description |
|---|---|---|---|
| adapter* | {} | - | |
| activeConversationId | string | - | |
| classes | Partial | - | Override or extend the styles applied to the component. See CSS classes API below for more details. |
| composerValue | string | - | |
| conversations | Array<{ avatarUrl?: string, id: string, lastMessageAt?: string, metadata?: ChatConversationMetadata, participants?: Array<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: any | any | any }>, readState?: 'read' | 'unread', subtitle?: string, title?: string, unreadCount?: number }> | - | |
| currentUser | { avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant' | 'system' | 'user' } | - | The local user sending messages. If omitted, derived from |
| density | 'comfortable' | 'compact' | 'standard' | 'standard' | The vertical spacing density of chat messages.
- |
| features | { attachments?: bool | bool | { acceptedMimeTypes?: Array<string>, maxFileCount?: number, maxFileSize?: number, onAttachmentReject?: func }, autoScroll?: bool | bool | { buffer?: number }, conversationHeader?: bool, helperText?: bool, scrollToBottom?: bool, suggestions?: bool } | - | Feature flags to enable or disable built-in ChatBox behaviours. |
| initialActiveConversationId | string | - | The initial active conversation ID when uncontrolled. Ignored after initialization and when |
| initialComposerValue | string | - | The initial composer value when uncontrolled. Ignored after initialization and when |
| initialConversations | Array<{ avatarUrl?: string, id: string, lastMessageAt?: string, metadata?: ChatConversationMetadata, participants?: Array<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: any | any | any }>, readState?: 'read' | 'unread', subtitle?: string, title?: string, unreadCount?: number }> | - | The initial conversations when uncontrolled. Ignored after initialization and when |
| initialMessages | Array<{ author?: { avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant' | 'system' | 'user' }, conversationId?: string, createdAt?: string, editedAt?: string, id: string, metadata?: ChatMessageMetadata, parts: Array<ChatDynamicToolMessagePart | ChatFileMessagePart | ChatReasoningMessagePart | ChatSourceDocumentMessagePart | ChatSourceUrlMessagePart | ChatStepStartMessagePart | ChatTextMessagePart | ChatToolMessagePart | {}>, role: 'assistant' | 'system' | 'user', status?: 'cancelled' | 'error' | 'pending' | 'read' | 'sending' | 'sent' | 'streaming', updatedAt?: string }> | - | The initial messages when uncontrolled. Ignored after initialization and when |
| localeText | Partial | - | |
| members | Array<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant' | 'system' | 'user' }> | - | All participants in the chat. The current (local) user is derived as the first member with |
| messages | Array<{ author?: { avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant' | 'system' | 'user' }, conversationId?: string, createdAt?: string, editedAt?: string, id: string, metadata?: ChatMessageMetadata, parts: Array<ChatDynamicToolMessagePart | ChatFileMessagePart | ChatReasoningMessagePart | ChatSourceDocumentMessagePart | ChatSourceUrlMessagePart | ChatStepStartMessagePart | ChatTextMessagePart | ChatToolMessagePart | {}>, role: 'assistant' | 'system' | 'user', status?: 'cancelled' | 'error' | 'pending' | 'read' | 'sending' | 'sent' | 'streaming', updatedAt?: string }> | - | |
| onActiveConversationChange | func | - | Signature: function(conversationId: string | undefined) => void |
| onComposerValueChange | func | - | Signature: function(value: string) => void |
| onConversationsChange | func | - | Signature: function(conversations: Array<ChatConversation>) => void |
| onData | func | - | Signature: function(part: ChatFallbackDataMessagePart<`data-${string}`>) => void | Promise<void> |
| onError | func | - | Signature: function(error: ChatError) => void |
| onFinish | func | - | Signature: function(payload: ChatOnFinishPayload) => void | Promise<void> |
| onMessagesChange | func | - | Signature: function(messages: Array<ChatMessage>) => void |
| onToolCall | func | - | Signature: function(payload: ChatOnToolCallPayload) => void | Promise<void> |
| partRenderers | { dynamic-tool?: func, file?: func, reasoning?: func, source-document?: func, source-url?: func, step-start?: func, text?: func, tool?: func } | - | |
| slotProps | ChatBoxSlotProps | - | The extra props for the slot components. |
| slots | Partial | - | The components used for each slot inside the ChatBox. See Slots API below for more details. |
| storeClass | ChatStoreConstructor | ChatStore | The store class to use for this provider. |
| streamFlushInterval | number | 16 | Flush interval in milliseconds for batching rapid streaming deltas before applying them to the store. |
| suggestions | Array<string | { label?: string, value: string }> | - | Prompt suggestions displayed in the empty state. Clicking a suggestion pre-fills the composer. |
| suggestionsAutoSubmit | bool | false | Whether clicking a suggestion automatically submits the message. |
| variant | 'compact' | 'default' | 'default' | The visual layout variant of the chat.
- |
| Slot name | Class name | Default component | Description |
|---|---|---|---|
| composerAttachButton | Override the composer attach button. | ||
| composerAttachmentList | Override the composer attachment list. | ||
| composerHelperText | Override the composer helper text component. | ||
| composerInput | Override the composer textarea component. | ||
| composerRoot | Override the composer (input) root component. | ||
| composerSendButton | Override the composer send button. | ||
| composerToolbar | Override the composer toolbar. | ||
| conversationHeader | Override the conversation header component. | ||
| conversationHeaderActions | Override the conversation header actions component. | ||
| conversationHeaderInfo | Override the conversation header info wrapper (title + subtitle column). | ||
| conversationList | Override the conversation list component. | ||
| conversationsPane | .MuiChatBox-conversationsPane | The conversations pane container. Defaults to `div`. | |
| conversationSubtitle | Override the conversation subtitle component. | ||
| conversationTitle | Override the conversation title component. | ||
| dateDivider | Override the date divider component. | ||
| layout | .MuiChatBox-layout | The layout element that arranges conversations + thread panes. Defaults to `div`. | |
| messageActions | Override the message actions component. | ||
| messageAvatar | Override the message avatar component. | ||
| messageContent | Override the message content (bubble) component. | ||
| messageGroup | Override the message group component. | ||
| messageList | Override the message list component. | ||
| messageMeta | Override the message meta component. | ||
| messageRoot | Override the message root component for each message. | ||
| root | .MuiChatBox-root | The outermost container element. Defaults to `div`. | |
| scrollToBottom | Override the scroll-to-bottom affordance component. | ||
| suggestions | Override the prompt suggestions container component. | ||
| threadPane | .MuiChatBox-threadPane | The thread pane container. Defaults to `div`. | |
| typingIndicator | Override the typing indicator component. | ||
| unreadMarker | Override the unread marker component. |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
| Class name | Rule name | Description |
|---|---|---|
| .MuiChatBox-conversationsPane | conversationsPane | Styles applied to the conversations pane element. |
| .MuiChatBox-layout | layout | Styles applied to the layout element. |
| .MuiChatBox-root | root | Styles applied to the root element. |
| .MuiChatBox-threadPane | threadPane | Styles applied to the thread pane element. |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.
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.