GhostChatMessage specification
Status: Approved on 2026-12-01 by @zprue743 for 0.4.0 (design approval; see the frontmatter evidence). This spec defines GhostChatMessage and the GhostVue chat building blocks as a set: which pieces ship as components or props, which stay documented recipes, and how they work together in a streaming chat. Two amendments ship with it: stickToBottom on GhostScrollArea and submitOnEnter on GhostTextarea.
Purpose and user problems
Apps built on GhostVue keep rebuilding the same chat view: a message log that follows streaming replies, message bubbles that sit on the sender's side, a composer where Enter sends and Shift+Enter breaks a line, and a typing indicator. Without library support, each app styles GhostCards as bubbles, uses a GhostBadge as the typing indicator, writes its own Enter handler (usually without IME handling), and sets scrollTop after every chunk (usually without letting the reader scroll up). Each one also has to work out, alone, how a screen-reader user hears new messages without hearing every streamed word.
GhostChatMessage is one message in a conversation: who sent it, which side it sits on, its content, and whether it is still arriving. It gives themes one styling target for bubbles and gives assistive technology a consistent per-message structure. The rest of the chat view is composed from existing components, two small amendments, and the recipe in this spec.
Non-goals
- A chat container, message list, or conversation component. The log is a
GhostScrollAreawithstickToBottomaround a consumer list. - A composer component. The composer is a form with
GhostTextarea(submitOnEnter) and a submit button. - Transport, streaming, message storage, retries, or optimistic updates. The app owns data; components render what they are given.
- Markdown rendering, syntax highlighting, attachments, reactions, threads, read receipts, or presence. Consumers put those in the default or
footerslot. - Message grouping (collapsing consecutive messages from one sender), date separators, and "new messages" dividers. These are recipe-level layout; a later spec can add them if apps keep rebuilding them.
- Virtualized history and loading older messages on scroll. See the ScrollArea non-goals.
- Announcing messages. The component adds no live region; the recipe owns one status region for the whole log (see Announcements).
Chat building blocks
Each piece from the app-builder report, and what ships for it:
| Piece | Ships as | Why |
|---|---|---|
| Log that follows streams | stickToBottom on GhostScrollArea (ST1–ST12) | The hard part is telling the reader's scroll from content growth without racing. It needs the scroll area's own observers, so it is a prop, not a recipe. |
| Message bubble | GhostChatMessage (new, headless and themed) | Side, status, and part structure must be the same in every app for themes and assistive technology. A recipe from GhostCard gave the wrong semantics and no side hook. |
| Typing indicator | status="typing" on GhostChatMessage | The indicator is a message that has not arrived yet. Modeling it as a message state keeps it in the log's order and lets it become the streaming reply in place. |
| Composer | submitOnEnter on GhostTextarea (SE1–SE7) plus the recipe | The Enter rules (IME, key repeat, read-only while sending) are easy to get wrong and are useful outside chat. The rest is an ordinary form, so no composer component. |
| Jump to latest | Recipe: GhostButton bound to v-model:stuck | Placement and wording vary by app; the state it needs is the stuck model. |
| New-message announcement | Recipe: one GhostVisuallyHidden role="status" region | What to announce (author, full text, a summary) is app policy. The spec fixes the pattern; see Announcements. |
The smallest slice that removes most custom code in the report is stickToBottom alone. This spec ships it with the message component and the composer prop because the maintainer chose to ship chat blocks in 0.4.0, and because those two are small, separable, and testable on their own.
Public API
Props and configuration
Headless @ghostvue/vue GhostChatMessage / useGhostChatMessage:
| Prop | Type | Default | Contract |
|---|---|---|---|
side | 'start' | 'end' | 'start' | Which inline side the message sits on. Logical, so end is the right side in LTR and the left in RTL. Conventionally end is the current user. Sets data-side. |
status | 'complete' | 'typing' | 'streaming' | 'complete' | Arrival state (CM2). typing renders the typing indicator instead of the default slot. Sets data-status. No aria-busy (CM5). |
typingLabel | string | 'Typing' | Visually hidden text read in place of the dots while status is typing. Consumers localize it, usually with the author ("Ada is typing"). |
type GhostChatMessageSide = 'start' | 'end'
type GhostChatMessageStatus = 'complete' | 'typing' | 'streaming'status describes arrival only. Delivery state (sent, failed, read) is app data and goes in the footer slot; a later prop for it would be additive.
Named ESM exports: GhostChatMessage, useGhostChatMessage, and the types above. Headless behavior lives in the composable; the SFC is a thin root that spreads rootProps and renders the parts.
Native attributes and listeners fall through to the root (id, class, style, data-*, lang, dir, aria-label, aria-labelledby). The component owns class, data-part, data-side, data-status, and the default aria-labelledby (CM4). A consumer aria-label or aria-labelledby replaces the default name.
Themed @ghostvue/themes GhostChatMessage wraps the unstyled component with the same props and no extra visual props. Importing it loads the default stylesheet and wraps the instance in .ghost-themed-scope.
v-model contracts
No model. side and status are consumer-owned configuration.
Events, callbacks, slots, and exposed methods
Slots, all optional:
| Slot | Part | Content |
|---|---|---|
avatar | avatar | Usually a GhostAvatar. When the header names the author, mark the avatar aria-hidden="true"; alt="" alone hides only an image, and initials fallbacks are still read. |
header | header | Author name and time (<time datetime>). Becomes the message's accessible name. |
default | bubble | Message content. Not rendered while status is typing. |
footer | footer | Delivery state, actions (copy, retry), reactions. |
A part's element is rendered only when its slot is provided, except bubble, which is always rendered so a typing message still has a bubble. No slot receives slot props.
No events. No exposed methods: the message has no imperative behavior, and consumers reach the root through an ordinary template ref on the component's $el.
useGhostChatMessage(options) returns rootProps, headerProps (which carries the generated header id), bubbleProps, avatarProps, footerProps, and typingProps, so a fully custom template can reproduce the same structure.
interface UseGhostChatMessageOptions {
side?: MaybeRefOrGetter<GhostChatMessageSide | undefined>
status?: MaybeRefOrGetter<GhostChatMessageStatus | undefined>
/** Whether a header is rendered; controls the default `aria-labelledby`. */
hasHeader?: MaybeRefOrGetter<boolean | undefined>
}State model
Message status
- CM1. Side is static configuration.
sidenever changes the DOM order or the reading order, onlydata-sideand the themed layout. - CM2. Status.
completeandstreamingrender the default slot inbubble.typingrenders the typing indicator inbubbleinstead of the default slot. Onlydata-statusdiffers betweencompleteandstreaming. Any transition is valid; the usual path for a reply istyping → streaming → completeon the same component instance (samekey), so the message keeps its place in the log and its DOM identity. - CM3. No timers. The component never changes
statusitself. An app that stops receiving a stream setscomplete(and shows an error in thefooter); the component does not time out.
Loading, empty, disabled, read-only, and error states
- Loading is
status="typing"or"streaming". - Empty: a
completemessage with an empty default slot renders an empty bubble. That is a consumer bug, not a state; the dev build does not warn because slot emptiness is unreliable to detect. - Disabled and read-only do not apply.
- Errors are app content in the
footerslot (for example aGhostInlineAlertand a retryGhostButton). The component has no error state;statusstays about arrival.
Async behavior
None. Streaming is the consumer updating slot content while status is streaming.
Consumer data
The component takes no data props beyond side, status, and typingLabel, and mutates nothing. Message text, authors, and times stay in the consumer's data and reach the component through slots. Message content is rendered by the consumer's slot markup, so the usual Vue escaping applies; a consumer that renders HTML from a model (v-html) owns sanitizing it.
Accessibility contract
Semantics and relationships
- CM4. One article per message. The root is a native
<article>. When theheaderslot is provided and the consumer passes neitheraria-labelnoraria-labelledby, the root getsaria-labelledbypointing at the header part's generated id (useGhostId), so screen-reader article navigation reads "Ada, 10:42" for each message. Without a header the article has no name, which is valid forarticle. - CM5. No
aria-busy. The component does not setaria-busyin any status. ARIA lets assistive technology withhold busy content, and some screen readers leave busy subtrees out of their browse buffer, which would hide the typing label and the partial reply exactly when CM6 and CM9 say they can be read. The log is not a live region (see Announcements), soaria-busyhas nothing to hold back. Adding it later forstreamingis additive and needs the manual assistive-technology evidence in the test plan first. - CM6. Typing indicator. The dots are
aria-hidden="true". The indicator's accessible content istypingLabelin a visually hidden span, so a reader moving through the log hears "Ada, Typing". - The recipe wraps messages in a list (
<ol role="list">, one<li>per message) so assistive technology reports the count and position. The explicitrole="list"keeps list semantics in WebKit when the themed log removes list markers.
Keyboard interaction
None. The message is not focusable and adds no key handlers. Interactive content in slots (links, buttons) keeps its native keyboard behavior and tab order.
Focus behavior
The component never moves or traps focus. In the recipe, focus stays in the composer while messages arrive. When a keyboard user activates "Jump to latest" (the button matches :focus-visible), the recipe moves focus to the composer before the button hides (see the trace, step 7). A pointer or touch activation leaves focus alone, so a phone's virtual keyboard does not open and shrink the log. ScrollArea ST6 keeps a keyboard-focused control inside an earlier message on screen while new content arrives.
Assistive technology expectations
A reader moving through the log hears, per message, the list position, the article name from the header, the content, and the footer. A message still arriving reads its current text; a typing message reads its typingLabel.
Announcements
The log must not be a live region. A role="log" or aria-live container announces every appended text node, so a streamed reply is read as a burst of fragments, and aria-busy does not reliably hold those back. Instead:
- CM7. One status region. The recipe renders one
<GhostVisuallyHidden role="status" aria-atomic="true">outside the scroll area.role="status"is a polite live region, so announcements wait for the reader's current speech and never move focus. Each announcement is written as a fresh change: the recipe clears the region, sets the new text on a later tick, and clears it again after a few seconds. That way two identical announcements in a row ("Message not sent" twice) are both spoken, and a browse-mode reader does not find a stale copy of the last message after the log. - CM8. Announce arrivals once. When a message from someone else arrives
completein one piece, the app announces the author and the full text ("Ada: The standup starts at nine."). When a streamed reply becomescomplete, the app announces the author and a short notice or the start of the text ("Assistant replied: The standup starts…"), not the whole reply, which can be long. Messages the user sent are not announced; they just typed them. - CM9. Announce a reply starting, never its chunks. When someone else's reply starts (
typingor the firststreamingchunk), the app may announce it once ("Assistant is replying"), so a screen-reader user is not left in silence until it completes. Streamed chunks and later typing changes are never announced. A reader who wants the partial reply can move into the log and read it. - CM10. Announce failures. When a send or a stream fails, the app announces it once through the same region ("Reply failed"). For a message that fails, the failure announcement replaces that message's arrival announcement rather than following it.
Announcements happen whether or not the log is following, so a reader who has scrolled up still hears new arrivals. The "Jump to latest" button also counts unread arrivals for sighted readers.
Rendering and customization
Single <article> root. Parts are direct children of the root in this DOM order: avatar, header, bubble, footer. Themes place them with CSS grid areas on the root; there are no wrapper elements to target.
Stable styling hooks:
- class
ghost-chat-messageon the root data-part="root" | "avatar" | "header" | "bubble" | "footer" | "typing" | "typing-dot"data-side="start" | "end"on the rootdata-status="complete" | "typing" | "streaming"on the root
The typing indicator is a typing part inside bubble holding three typing-dot spans (all under aria-hidden="true") and the visually hidden typingLabel.
Themed CSS under .ghost-theme / .ghost-themed-scope:
- Grid layout with the avatar column on the message's side, the header above the bubble, and the footer below it.
endmessages align to the inline end. - Bubble:
--ghost-surface-muted-bg/--ghost-surface-fgforstart,--ghost-action-primary-bg/--ghost-action-primary-fgforend, radius--ghost-radius-lg, inline size capped (about 80% of the log, at most roughly 40rem) so long messages wrap. Links inside anendbubble usecurrentColorand stay underlined so they keep contrast on the primary background.pnpm contrastmust pass for both pairs in every theme and mode. - A 1px transparent border on the bubble, so bubbles stay outlined in forced colors mode.
- Long unbroken strings (URLs, tokens) wrap with
overflow-wrap: anywhere. - Typing dots pulse with
--ghost-motion-duration-slow. Underprefers-reduced-motion: reducethey are static, asGhostSpinner's reduced-motion rule does for rotation. - Logical properties only, so RTL mirrors sides without extra rules.
The themed recipe adds no component tokens. If the build finds a theme where a pair fails contrast, it adds semantic chat tokens through the token pipeline in the same PR rather than hard-coding colors.
Environment behavior
SSR and hydration
All markup is deterministic from props and slots. The header id comes from useGhostId, which is SSR-stable. No browser APIs are used, so there is no mount-time work. An integration test uses expectSsrHydration for each status.
Mobile and touch
No gestures. Themed bubbles cap their width relative to the log, so narrow screens keep a visible side offset. Touch targets inside slots keep their own sizes; the recipe's footer actions use GhostButton sizes that meet --ghost-control-touch-min on coarse pointers.
Performance
A message is one element plus up to four parts, with no watchers beyond its props and no observers. Streaming re-renders only the slot content of the one streaming message when the consumer keys messages by id. The recipe keys <li> elements by message id so appends never re-render earlier messages. Logs of a few thousand messages are the expected ceiling, the same as ScrollArea's.
Composition
GhostScrollAreawithstickToBottomandv-model:stuckis the log.GhostTextareawithsubmitOnEnter,autoResize, andmaxRowsinside a<form>orGhostFormis the composer.GhostAvatargoes in theavatarslot;GhostButtonfor "Jump to latest", send, and footer actions;GhostInlineAlertfor failed messages;GhostVisuallyHiddenfor the status region and the typing label.useGhostIdnames the header. No new shared primitive is added.
GhostCard is deliberately not reused for bubbles: a card is a sectioning surface with its own padding and elevation recipe, and a bubble needs side alignment, tighter spacing, and a different surface per side.
End-to-end streaming chat
This trace is the acceptance scenario for the build. It uses the themed components:
<template>
<section class="chat" aria-labelledby="chat-title">
<h2 id="chat-title">Support chat</h2>
<GhostScrollArea
ref="log"
v-model:stuck="following"
stick-to-bottom
label="Conversation"
class="chat-log"
>
<ol class="chat-messages" role="list">
<li v-for="message in messages" :key="message.id">
<GhostChatMessage
:side="message.mine ? 'end' : 'start'"
:status="message.status"
:typing-label="`${message.author} is typing`"
>
<template #avatar>
<GhostAvatar :name="message.author" aria-hidden="true" />
</template>
<template #header>
{{ message.author }}
<time :datetime="message.at">{{ formatTime(message.at) }}</time>
</template>
{{ message.text }}
<template v-if="message.failed" #footer>
<GhostInlineAlert tone="danger">Not delivered.</GhostInlineAlert>
</template>
</GhostChatMessage>
</li>
</ol>
</GhostScrollArea>
<GhostButton v-if="!following" @click="jumpToLatest">
Jump to latest<template v-if="unread"> ({{ unread }} new)</template>
</GhostButton>
<GhostVisuallyHidden role="status" aria-atomic="true">
{{ announcement }}
</GhostVisuallyHidden>
<form class="chat-composer" @submit.prevent="send">
<GhostTextarea
ref="composer"
v-model="draft"
submit-on-enter
auto-resize
:max-rows="6"
:readonly="sending"
enterkeyhint="send"
aria-label="Message"
aria-describedby="composer-hint"
/>
<p id="composer-hint">Enter to send, Shift+Enter for a new line</p>
<GhostButton type="submit" :loading="sending">Send</GhostButton>
</form>
</section>
</template>The script (not shown) keeps messages, draft, sending, following, unread, and announcement in refs. The exact prop names of GhostAvatar, GhostInlineAlert, and GhostButton follow their current manifests; the build's executable example is the source of truth. The layout is a column whose log takes the remaining height (min-block-size: 0; flex: 1), so the composer growing shrinks the log rather than the page.
- Open. The log mounts with
followingtrue and scrolls to the newest message before the first client paint (ST3). "Jump to latest" is hidden. Nothing is announced. - Send. The user types and presses
Enter. SE1 callsrequestSubmit(); the form'ssubmithandler ignores an empty or whitespace-only draft, and otherwise appends the user's message (side="end",complete), clearsdraft, and setssendingwhile the request is in flight, which makes a secondEntera no-op (SE6). Focus stays in the composer. The new message grows the log, and the composer shrinking back to one row grows the log's box; both keep the view at the bottom (ST4). The user's own message is not announced (CM8). - Typing. The app appends the reply as
status="typing". The view follows. The status region says "Assistant is replying" once (CM9). - Streaming. The first chunk switches the same message to
streamingand each chunk appends text. Every chunk grows the content, and the view follows in the same frame (ST4). Nothing is announced (CM9). - Reader scrolls up. Mid-stream, the user scrolls up with the wheel. The wheel starts a hold that pauses following before the browser scrolls, and the resulting upward scroll releases (ST5);
update:stuck(false)setsfollowingfalse, and "Jump to latest" appears. Later chunks grow the content below the viewport and the view stays where the reader put it. - Reply completes. The app sets
status="complete", writes "Assistant replied: …" with the start of the text into the status region (CM7, CM8), and, becausefollowingis false, incrementsunread. The button reads "Jump to latest (1 new)". Screen-reader users hear the reply even though the view is not at the bottom. - Return. The user activates "Jump to latest". If the button matches
:focus-visible(keyboard activation),jumpToLatestfirst focuses the composer through its exposedfocus(); a tap or click leaves focus alone. It then setsfollowingto true andunreadto 0. Setting the model scrolls to the bottom instantly (ST8) and the button disappears. A keyboard user's focus is already somewhere that persists. - Keyboard reading. A keyboard user tabs back from the composer into a link in an earlier message. The browser scrolls the link into view, which moves the view up and releases following (ST5 item 2); later chunks do not pull the link away (ST6 covers the case where keyboard focus lands without a scroll). In a log with no tabbable content, the root is the tab stop and
ArrowUpreleases,Endre-engages. - Failure. A stream drops. The app sets the reply
complete, renders the footer alert, and announces "Reply failed" once in place of the arrival announcement (CM10).
Test plan
- Composable tests:
rootPropsdefaults (articleattributes,data-side="start",data-status="complete"); each status, none of which setsaria-busy;aria-labelledbyonly whenhasHeaderand no consumer name; part props. - Vue tests: each slot renders its part only when provided, in DOM order avatar, header, bubble, footer;
bubblealways present;typingrenders the dots witharia-hiddenand thetypingLabeltext, and does not render the default slot;streamingrenders the default slot;typing → streaming → completekeeps the same root element; consumeraria-labelandaria-labelledbywin over the default; attribute and class fallthrough; header id stable between SSR and client. - Integration:
expectSsrHydrationfor each status, with and without a header. - Browser (Playwright) on the streaming chat example: steps 1–9 of the trace, asserting visible last line while following, release on wheel and on
Homein a text-only log, the button's unread count, focus on the composer after a keyboard activation of "Jump to latest" (toBeFocused()) and no focus move after a click,EnterandShift+Enterin the composer, an empty draft not sending, and the status region's text after a reply starts, after it completes, after a failure, and for two identical announcements in a row (both written as fresh changes, region cleared afterwards). The avatar is absent from the accessibility tree when the header names the author. Axe scans with a typing message, a streaming message, and a failed message, following on and off. RTL run assertingendbubbles sit on the left. - Themed checks:
pnpm contrastfor both bubble pairs; computed bubble colors per side; forced-colors emulation shows a bubble border; reduced motion stops the dots. - Type tests:
sideandstatusreject other strings; slot names are typed. - Visual baselines: the registered chat examples via
pnpm test:visual:docker. - Framework-neutral unit tests: none; the component owns no core logic.
- Manual assistive-technology matrix (planned for the build, recorded in the manifest's
accessibility.verificationwhen run): NVDA with Firefox and Chrome, JAWS with Chrome, VoiceOver on macOS Safari and iOS Safari, and TalkBack with Chrome. On the streaming example, check one announcement per reply start and completion, no chunk announcements, the typing label and the partial streaming text readable in browse mode, and article navigation reading the header name.
Documentation plan
- New
docs/components/chat-message.md: API reference (generated tables), sides, statuses including typing, slots, styling hooks, and accessibility notes covering CM4–CM10. - A "Build a chat" section on that page with the full streaming chat example (
examples/chat-message/streaming-chat.vue), which simulates a stream with timers and covers every step of the trace. Smaller examples:examples/chat-message/sides.vueandexamples/chat-message/typing.vue. - Cross-links from the ScrollArea "Stick to bottom" and Textarea "Submit on Enter" sections to the chat page.
- Playground: a chat exercise using the streaming example.
- Roadmap: the build adds a row for
GhostChatMessageand changes only that row.
Compatibility and release impact
Additive. GhostChatMessage and useGhostChatMessage are new exports in @ghostvue/vue, and the themed GhostChatMessage is new in @ghostvue/themes, each with a minor Changeset and experimental manifest status. The ScrollArea and Textarea amendments are opt-in props on existing components and do not change existing behavior.
Public contracts introduced: the three props and their unions, the four slots, the part names and data-* hooks above, the article root, the default aria-labelledby, and the absence of aria-busy. Changing the root element, the part order, or the default name later needs a compatibility review.
Open architectural questions
None blocking.
- Delivery status. Deferred.
statuscovers arrival only; sent, failed, and read states are footer content for now. Adeliveryprop could be added without breaking anything if apps converge on one model. - Grouping and separators. Deferred to a later spec if the recipe proves repetitive (see Non-goals).