Hello! I am styled using your active Material UI theme. Try sending a message.
Chat - Slot overrides
Swap individual subcomponents of the Chat with your own implementations to customize rendering and layout.
The slots prop lets you swap any internal component in ChatBox with your own implementation.
The demo below replaces the message bubble with a Paper-based component that uses Material UI elevation and border styles:
- A custom
slots.contentwraps the defaultChatMessageContent. - The inner
bubbleslot ofChatMessageContentis replaced with a Material UIPapercomponent. ownerState.roledifferentiates user and assistant bubble styling.sxonPaperuses theme tokens (primary.main,background.paper,divider) for consistent colors.
Wrapping the default slot
The recommended way to override a slot is to wrap the default component and replace only its inner slots:
import { ChatMessageContent } from '@mui/x-chat';
const CustomMessageContent = React.forwardRef(
function CustomMessageContent(props, ref) {
return (
<ChatMessageContent
ref={ref}
{...props}
slots={{ ...props.slots, bubble: MyBubble }}
/>
);
},
);
<ChatBox slots={{ messageContent: CustomMessageContent }} />;
This keeps the default rendering behavior—part iteration, reasoning blocks, source citations, and tool invocations—and only changes the visual container.
Styling slots with ownerState
Slot components receive an ownerState prop from the Material UI styled system.
For message-related slots, ownerState.role is 'user' or 'assistant':
function MyBubble({ ownerState, children, ...props }) {
const isUser = ownerState?.role === 'user';
return (
<div style={{ background: isUser ? 'blue' : 'white' }} {...props}>
{children}
</div>
);
}
Destructure ownerState before spreading remaining props so it never reaches DOM elements that don't support it.
Implementation notes
- Custom slot components must accept a
refif the default component uses one. - Spread
...propsafter destructuringownerStateto forward all remaining props correctly. - Use the
slotsprop onChatBoxrather than on individual subcomponents when wiring from the top level.
See also
- See Customization for details on the available slot keys and their default components.
- See Custom theme for details on retheming without replacing components.