Components/Message Actions

Message Actions

A message toolbar with built-in copy, regenerate, and read-aloud actions.

VerifiedSince 0.3.9

Usage

Basic

Loading demo...

Best Practices

  • Use native <button>s, or elements with a tabindex, for custom actions; non-focusable elements stay out of the arrow-key order.
  • copy fires even when the clipboard write fails; handle any fallback there instead of copying a second time.
  • When localizing, override copyLabel, copiedLabel, regenerateLabel, speakLabel, stopSpeakLabel, and label together.
  • Mount the toolbar after the message finishes streaming, so nobody copies a half-written answer.

API Reference

Props

NameTypeDefaultDescription
copyTextstring—Text the copy button writes; without it, no copy button renders.
regenerablebooleanfalseShows the regenerate button.
speakablebooleanfalseShows the read-aloud button; the host owns playback.
speakState'idle' | 'loading' | 'speaking''idle'Playback state set by the host: loading shows a spinner, speaking a stop icon.
appearbooleantruePlays a blur-fade entrance on mount.
copyLabelstring'Copy'Accessible name and hover tooltip of the copy button.
copiedLabelstring'Copied'Accessible name and hover tooltip in the copied state.
regenerateLabelstring'Regenerate'Accessible name and hover tooltip of the regenerate button.
labelstring'Message actions'Accessible name of the toolbar.
speakLabelstring'Read aloud'Accessible name and hover tooltip of the read-aloud button.
stopSpeakLabelstring'Stop reading'Accessible name and hover tooltip of the read-aloud button while speaking.

Events

NamePayloadDescription
copy(text: string)Fires after a copy click with copyText, even if the clipboard write failed.
regenerate—Fires when regenerate is clicked.
speak—Fires when the read-aloud button is clicked.

Slots

NameDescription
defaultAppended after the built-in buttons; focusable elements in it join the arrow-key order.

Overview

  • An empty-string copyText still renders the copy button, but clicking does nothing; omit the prop to hide it.
  • Copying writes through navigator.clipboard; the button then shows its copied state for 1200ms and ignores repeat clicks.
  • The read-aloud button is a toggle: every click emits speak, even while loading, and the host starts or stops playback; aria-pressed is true while speaking.
  • The bar is a role="toolbar": one Tab stop, arrow keys cycle through the controls, and Home / End jump to the ends.
  • The arrow-key order is read live from the DOM (button:not([disabled]), [href], any non--1 tabindex), so disabled buttons are excluded.