Skip to content

GhostChatMessage ​

GhostChatMessage is one message in a conversation: who sent it, which side it sits on, its content, and whether it is still arriving. Import it from @ghostvue/themes for chat bubbles. A whole chat view is composed from it, GhostScrollArea with stickToBottom, and GhostTextarea with submitOnEnter, as the next example shows. To style messages yourself, see Advanced: headless composition.

Build a chat ​

Streaming support chat

Log that follows a streamed reply, stops when the reader scrolls up, offers Jump to latest with an unread count, and announces arrivals in one status region.

Support chat

  1. Assistant
    Hi! How can I help with your workspace today?
  2. You
    Our nightly report export did not arrive this morning.
  3. Assistant
    Sorry about that. Which workspace is it, and when did the last export arrive?
  4. You
    Workspace "Northwind ops". The last one came on Sunday night.
  5. Assistant
    Thanks. Is anything else failing, or only the export?
  6. You
    Only the export. Dashboards still load fine.

Enter to send, Shift+Enter for a new line

Type a message and press Enter. The assistant's reply arrives as a typing indicator, then streams in word by word, and the log follows it. Scroll up while it streams: the log stops following and Jump to latest appears with a count of replies that finished while you were away. Check Simulate a dropped connection to see a failed reply.

The example puts the pieces together like this:

  • Log. A themed GhostScrollArea with stick-to-bottom, a label, and v-model:stuck="following" wraps an <ol role="list"> with one <li> per message, keyed by message id. The explicit role="list" keeps list semantics in WebKit after the bullets are removed. The log is a flex child with min-block-size: 0; flex: 1, so the composer growing shrinks the log instead of the page.
  • Messages. side="end" for the current user, status for arrival, and typing-label with the author's name. The reply is one message that goes typing → streaming → complete on the same component instance, so it keeps its place and DOM identity.
  • Jump to latest. A button shown while following is false. Clicking it sets following to true, which scrolls to the bottom instantly. When it was activated from the keyboard (the button matches :focus-visible), focus moves to the composer first; a click or tap leaves focus alone so a phone's keyboard does not open.
  • Composer. A <form> with a GhostTextarea (submit-on-enter, auto-resize, max-rows, readonly while sending, enterkeyhint="send") and a visible key hint wired through aria-describedby. The form's submit handler ignores an empty draft.
  • Announcements. One status region, described below.

Sides ​

Sides

Messages from another person on the start side and from the current user on the end side, each named by its header.

  1. Ada Lovelace
    Can you review the release notes before the 2 PM cut?
  2. You
    On it. I will leave comments in the draft by 1:30.

side is start (the default) or end. It is logical: in a right-to-left layout end sits on the left. It only changes data-side and the themed layout, never the DOM order or reading order. Conventionally end is the current user. The themed recipe colors start bubbles with the muted surface and end bubbles with the primary action colors; links in an end bubble use the text color and stay underlined.

Typing and streaming ​

Typing indicator

A reply that has not arrived yet, with animated dots and a visually hidden typing label.

  1. You
    Is the staging deploy finished?
  2. Grace Hopper
    Grace Hopper is typing

status describes arrival only:

statusBubble shows
completeThe default slot. The default status.
typingThree dots and the visually hidden label.
streamingThe default slot as it grows, chunk by chunk.

The dots are hidden from assistive technology; a screen reader reads typingLabel instead ("Grace Hopper is typing"). The themed dots pulse, and are static under prefers-reduced-motion: reduce. The component never changes status on its own and never times out; when a stream stops, set complete and show the error in the footer slot. Delivery state (sent, failed, read) is your data and also goes in the footer.

Slots ​

SlotPartUse for
avataravatarA GhostAvatar. Add aria-hidden="true" when the header names the author.
headerheaderAuthor and <time datetime>. Names the message.
defaultbubbleMessage content. Not rendered while status is typing.
footerfooterDelivery state, errors (GhostInlineAlert), and actions such as Copy, Retry.

Each part is rendered only when its slot is provided, except bubble, which is always there. Message text is rendered by your slot markup, so Vue escapes it; if you render HTML from a model with v-html, sanitize it yourself.

Accessibility ​

  • One article per message. The root is an <article>. With a header slot it is named by the header (aria-labelledby), so screen-reader article navigation reads "Ada, 10:42" for each message. A consumer aria-label or aria-labelledby replaces that name. Without a header the article has no name, which is valid.
  • No aria-busy. Some screen readers leave busy content out of browse mode, which would hide the typing label and the partial reply.
  • Not a live region. Do not put role="log" or aria-live on the log: it would read a streamed reply as a burst of fragments. Use one status region.
  • Focus. The message is not focusable and adds no key handlers. Links and buttons in slots keep their own tab order. GhostScrollArea never scrolls a keyboard-focused control in an earlier message out of view.

Announcements ​

Render one <GhostVisuallyHidden role="status" aria-atomic="true"> outside the log. role="status" is polite, so announcements wait for current speech and never move focus. Write each announcement as a fresh change: clear the region, set the text on a later tick, and clear it again after a few seconds. Then two identical announcements in a row are both spoken, and browse mode does not find a stale copy after the log.

WhenAnnounce
Someone else's message arrives completeAuthor and full text ("Ada: The standup…")
Someone else's reply starts typing/streamingOnce: "Assistant is replying"
A streamed reply completesAuthor and the start of the text, not all of it
A send or stream failsOnce: "Reply failed", instead of the arrival
Your own message, each streamed chunkNothing

Announcements happen whether or not the log is following, so a reader who has scrolled up still hears new replies.

Advanced: headless composition ​

For teams that bring their own design system, the headless GhostChatMessage from @ghostvue/vue renders the same article and parts with no styles. useGhostChatMessage({ side, status, hasHeader }) returns rootProps, avatarProps, headerProps (with the generated header id), bubbleProps, footerProps, and typingProps so a fully custom template can reproduce the same structure.

Styling hooks ​

Parts are direct children of the root in the order avatar, header, bubble, footer, so place them with grid areas on the root; there are no wrapper elements. Hooks:

  • class ghost-chat-message on the root
  • data-part="root" | "avatar" | "header" | "bubble" | "footer" | "typing" | "typing-dot"
  • data-side="start" | "end" and data-status="complete" | "typing" | "streaming" on the root
css
.ghost-chat-message[data-side='end'] > [data-part='bubble'] {
  background: var(--brand-bubble-bg);
}

API ​

PropTypeDefaultDescription
sideGhostChatMessageSide"start"Which inline side the message sits on. Never changes DOM or reading order, only data-side and the themed layout.
statusGhostChatMessageStatus"complete"Arrival state. typing renders the typing indicator instead of the default slot. The component never sets aria-busy.
typingLabelstring"Typing"Visually hidden text read in place of the typing dots while status is typing. Localize it, usually with the author ("Ada is typing").
SlotSlot propsDescription
avatar—Avatar part, usually a GhostAvatar. Mark it aria-hidden when the header names the author.
default—Bubble content. Not rendered while status is typing.
footer—Footer part for delivery state, errors, actions, and reactions.
header—Header part with author and time. Becomes the article's accessible name.

@ghostvue/themes adds no props, events, or slots to the headless GhostChatMessage API, which it forwards.

See the GhostChatMessage specification for the complete behavior and compatibility contract.