Message Thread
betaA compact chat thread whose sent bubbles lift out of the field while older messages glide up.
- Data
- 1 file
- 1 npm package
- Accessibility notes
Loading the example…
pnpm dlx @dowel-ui/cli add message-threadnpm packages installed: class-variance-authority.
import { MessageThread } from "@/components/ui/message-thread";Default
Demo
Typing
<MessageThread>
| Prop | Type | Default |
|---|---|---|
contactNameThe other person's name, announced before their messages. | string | "Them" |
defaultMessagesInitial thread when uncontrolled. Sent messages are appended for you. | ThreadMessage[] | [] |
defaultValueInitial draft when uncontrolled. | string | "" |
disabled | boolean | false |
messagesControlled thread, oldest first. Append the sent message yourself in | ThreadMessage[] | — |
onMessagesChange | (messages: ThreadMessage[]) => void | — |
onSendCalled with the trimmed text when the viewer sends. | (text: string) => void | — |
onValueChange | (value: string) => void | — |
placeholderPlaceholder and accessible name of the field. | string | "Message" |
sendLabelAccessible name of the send button. | string | "Send" |
size | "sm" | "md" | "lg" | "md" |
threadLabelAccessible name of the thread. | string | "Messages" |
typingShow the other person typing. | boolean | false |
valueControlled draft. | string | — |
Plus every attribute of <div> except children, defaultValue, onChange.
The thread is role="log", named "Messages", so new messages are announced politely as they arrive, and it is focusable so the history can be scrolled from the keyboard. Every bubble begins with visually hidden "You:" or "<contactName>:", so the sender never depends on colour or side, and the typing indicator says "<contactName> is typing" in words with its dots aria-hidden. The field is named by its placeholder and submits on Enter; the send button is named "Send" and is disabled while the field is empty. Layout is logical, so the sides swap in right-to-left languages. Under reduced motion messages appear without the lift and the typing dots stay still.
10/10
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — passes
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — passes
- No fixed widths — passes