affectUI › Components › Chat

Message Actions

The quiet bar under an AI message – copy turns into a check, regenerate spins and unfolds a version switcher, thumbs pop and ask why, read aloud becomes a tiny equalizer.

Free and open source (MIT). Install: npx shadcn@latest add https://www.affectui.com/r/message-actions.json · Import from @/components/ui/message-actions

When to use

  • Under every assistant message in a chat – copy, try again, rate and listen without leaving the conversation
  • Wherever a model can answer more than once and people should be able to flip between the answers
  • When you collect feedback on answers and want a reason, not just a thumb

When not to use

  • Under the user's own messages – edit and delete fit there better than regenerate and rating
  • For a long list of actions – keep it to the four; put the rest in a menu
  • When the answer is still streaming – show a stop button instead and bring the bar in once it is done

Usage

import { MessageActions, MessageText } from "@/components/ui/message-actions";

export function AssistantMessage({ message }) {
  const [version, setVersion] = useState(message.versions.length - 1);
  const text = message.versions[version];

  return (
    // data-ui-message lets the bar light up while the whole message is hovered
    <div data-ui-message>
      <MessageText version={version}>{text}</MessageText>
      <MessageActions
        text={text}
        versions={message.versions}
        version={version}
        onVersionChange={setVersion}
        onRegenerate={() => regenerate(message.id)}
        onFeedback={(kind, reason) => saveFeedback(message.id, version, kind, reason)}
      />
    </div>
  );
}

Props

NameTypeDefaultDescription
textstringThe message text – Copy writes it to the clipboard, and an uncontrolled read aloud is timed by its length
actionsMessageActionKey[]["copy", "regenerate", "feedback", "speak"]Which actions to show and in what order. feedback is the thumbs up and down
versionsnumber | string[]1All versions of the message, or just how many there are. From two on the "‹ 2 / 3 ›" switcher unfolds next to Regenerate
versionnumberControlled version, 0-based
defaultVersionnumbernewestStarting version when uncontrolled. Uncontrolled, the switcher jumps to a version as soon as it is added
onVersionChange(index: number) => voidCalled with the version picked in the switcher
onCopy(text?: string) => voidCalled after Copy, with text
onRegenerate() => voidCalled when Regenerate is pressed – add a version to versions and it shows up in the switcher
regeneratingbooleanfalseKeeps the arrow spinning and the bar lit while a new version is written
onFeedback(kind: "up" | "down" | null, reason?: string) => voidCalled with the vote right away, with null when it is taken back, and once more with "down" and a reason when the feedback row is sent. A new version starts without a vote
reasonsstring[]Not accurate, Too long, Didn't follow instructions, OtherQuick reasons in the feedback row. "Other" unfolds a small text field whose words are sent as the reason
onSpeak(playing: boolean) => voidCalled with true when Read aloud starts and false when it stops
speakingbooleanControlled playing state – tie it to your speech player. Without it the bar plays for speakDuration and stops on its own
speakDurationnumberfrom text, at least 2600How long an uncontrolled read aloud plays, in ms
quietbooleantrueFaded until the message (an ancestor with data-ui-message) or the bar is hovered or focused. Touch screens always show it fully
labelstring"Message actions"Accessible name of the bar
classNamestringExtra class on the root

Keyboard

  • Tab: Through the actions, the version arrows and – when it is open – the reasons and Send
  • Enter / Space: Presses an action, picks or drops a reason, sends
  • Enter: In the "Other" text field: sends
  • Esc: Closes the feedback row and puts focus back on thumbs down

Accessibility

  • Each action is a button with its own name; the thumbs and Read aloud are toggle buttons with aria-pressed, thumbs down has aria-expanded for the feedback row
  • Tooltips repeat the button names, so they are hidden from screen readers; they also show on keyboard focus
  • Copied, the version you switched to, Reading aloud and Thanks are announced through a polite live region
  • The version arrows are disabled at either end, and the count is read as "Version 2 of 3"
  • While closed, the feedback row is inert – nothing hidden can be focused

Responsive

  • The bar is about 230px wide with the switcher; the feedback row fills its container up to 440px and its reasons wrap
  • Below 320px the Send button takes its own line under the reasons
  • Touch screens: 38px buttons, taller reasons, no hover tooltips (only "Copied"), and the bar is never faded
  • Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"

Requirements

  • React 19

Related

  • AI Answer – Streamed answer with source cards, citation chips that preview their source, copy, regenerate, feedback and follow-ups
  • Reaction Bar – Like, comment, repost and share in one pill – icons pop and fill, counts roll in digit by digit
  • Chat Composer – Prompt composer with model picker, voice input, app connections and approval request
  • Thinking State – AI working panel with a live timer, searched sources and thinking steps that appear one by one

Guides