Components/Message Actions

Message Actions

A message toolbar with built-in copy and regenerate 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, 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.
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.

Events

NamePayloadDescription
copy(text: string)Fires after a copy click with copyText, even if the clipboard write failed.
regenerate—Fires when regenerate 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 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.