Components/Message Actions

Message Actions

A message toolbar with built-in copy and regenerate, navigated with arrow keys.

VerifiedSince 0.3.9

Message Actions

Basic Usage

Message Actions

Loading demo...

Interaction Contract

  • The copy button renders whenever copyText is defined — an empty string still renders it, though clicking does nothing. Omit the prop entirely to hide it.
  • Copying writes through navigator.clipboard. The copy event is emitted even when that write is denied by permissions policy, so the host can route the copy through its own channel.
  • After a copy the button shows its copied state for 1200 ms and ignores repeat clicks during that window.
  • The bar is role="toolbar": a single tab stop, with ← → ↑ ↓ moving between controls and Home / End jumping to the ends.
  • The roving order is read live from the DOM (button:not([disabled]), [href], any non--1 tabindex), so focusable elements in the default slot join the same order with no extra wiring.
  • Disabled buttons are excluded from the roving order.
  • With appear set, a slow blur-fade entrance plays once on mount. Turn it off explicitly where an entrance is unwanted.

API

Props

NameTypeDefaultDescription
copyTextstringThe text the copy button writes. The button is not rendered when this is omitted.
regenerablebooleanfalseWhether to show the regenerate button.
appearbooleantrueWhether to play the blur-fade entrance on mount.
copyLabelstring'Copy'Accessible name for the copy button.
copiedLabelstring'Copied'Accessible name while in the copied state.
regenerateLabelstring'Regenerate'Accessible name for the regenerate button.
labelstring'Message actions'Accessible name for the toolbar itself.

Events

NamePayloadDescription
copy(text: string)Emitted after a copy click with copyText, including when the clipboard write failed.
regenerateEmitted when regenerate is clicked.

Slots

NameDescription
defaultAppended after the built-in buttons. Focusable elements placed here join the arrow-key roving order automatically.

Best Practices

  • Use native <button> elements for custom actions. The roving order is found by tag and tabindex, so a wrapping <div> is skipped.
  • Do not re-implement the copy as a fallback for clipboard failures — listen to copy, which the component already emits in both cases.
  • Override copyLabel, copiedLabel, regenerateLabel and label together when localizing; all four affect accessible names only, not the visuals.
  • Hold the toolbar back until a message finishes streaming, or users will copy a half-written answer.