Chat
Message
One message in a chat: who wrote it, their avatar and what they wrote, with any attachments under it. role places and colors it: the user's own messages at the end in the primary color, the assistant's at the start, the app's system notes centered. streaming marks a reply still being written.
Install
Once per app, with Tailwind CSS v4 and an @/* path alias (Ouro HX is built on Base UI, so --base base; skip -t in an existing app):
npx shadcn@latest init --base base --preset nova --yes --no-monoreponpx shadcn@latest add ourostack/ouro-ui/ouro-base#v1.2.13Then the component. From v0.8.0 it installs only the helpers it imports and never touches your stylesheet (Installing):
npx shadcn@latest add ourostack/ouro-ui/message#v1.2.13Or, with the @ouro namespace set up:
npx shadcn@latest add @ouro/ouro-base @ouro/messageIts tests, stories and Playwright spec are optional. They need Vitest 4.1.11 or later, and from v0.8.0 never change a version your app has (Testing):
npx shadcn@latest add ourostack/ouro-ui/message#v1.2.13 ourostack/ouro-ui/message-tests#v1.2.13import { Message } from "@/components/ouro/message/message";Paths use shadcn's default @/ alias; the CLI rewrites them to yours.
Example
<Message role="user" name={user.name} avatar={user.photoUrl}>How long do I rest the dough?</Message>
<Message role="assistant" name="Ouro" streaming={!reply.done}>{reply.text}</Message>Usage
Use it inside MessageList, which keeps the newest message in view and announces new ones.
Use instead when
- Use
Alertinstead for a notice that is not part of a conversation, andtoast()for a passing confirmation.
Props
Type: MessageProps.
attachments- Type:
ReactNode - Files sent with the message, shown under it:
<Attachment>elements. avatar- Type:
string | false - The author's picture URL. Without it the avatar shows initials;
falseshows no avatar. children- Type:
ReactNode - The message: text, or rich content such as a list or a code block.
className- Type:
string - Layout only: margins (
mt-4). Appearance classes warn in development; the colors followrole. name(required)- Type:
string - The author's name. Screen readers hear it before the message, and the avatar's initials come from it. Required, so every message says who wrote it. The user's own name is read but not shown.
ref- Type:
Ref<HTMLElement> - Reaches the rendered element.
role(required)- Type:
"user" | "assistant" | "system" - Who wrote it.
useris the person using the app: their messages sit at the end, in the primary color.assistantis anyone else, such as an agent, at the start.systemis the app's own note ("Ada joined"), centered and quiet. streaming- Type:
boolean - The reply is still being written. The message is
aria-busy, an empty one shows a typing indicator, andMessageListannounces it once, when streaming ends. streamingLabel- Type:
string - Default:
"Writing" - What screen readers hear for the typing indicator, for other languages.
Native attributes
Also accepts the attributes in React's HTMLAttributes (id, aria-*, event handlers), passed to the rendered element, except those named on this page.
Don't use
These are not props. Passing one fails the type check with the fix in the error, and in development a console message names the fix.
author: Not a prop. The author isname:<Message role="user" name="Ada">.content: Not a prop. The message is the children:<Message role="user" name="Ada">Hi</Message>.from: Not a prop. Who wrote it isrole:<Message role="user" name="Ada">.sender: Not a prop. The author isname:<Message role="user" name="Ada">.
className is for layout only
Pass margins, width and grid placement (mt-4, w-full, col-span-2). Your classes always win over Ouro UI's: Message merges className last with cn (tailwind-merge), so a class that conflicts with its own replaces it.layout-classes
Appearance comes from props, not classes. In development, a class that sets appearance logs one warning per component instance, naming the prop to use instead. A class sets appearance when, after its variants (hover:, sm:) and any ! are removed, it starts with bg-, text-, border-, rounded-, shadow-, font-, ring-, from-, via-, to-, fill- or stroke-, or is border, rounded, shadow or ring, or has a dark: variant. Text wrapping, overflow and table layout classes (text-wrap, text-ellipsis, border-collapse) are layout and do not warn.
Alignment classes (text-center) warn too: set alignment on a parent element.
Claim sources
- layout-classes: test:registry/ouro/components/ouro/message/message.test.tsx::Message > forwards a ref and lets app layout classes win
verify:testExists(registry/ouro/components/ouro/message/message.test.tsx::Message > forwards a ref and lets app layout classes win)