# Chat Message Actions

Copy / retry / thumbs up-down actions shown under an assistant message.

- Category: AI & Agents
- Page: https://wunderui.com/components/chat-message-actions
- Tier: Core and Pro

## Install

Chat Message Actions ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { ChatMessageActions } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { useState } from "react"
import { ChatMessageActions } from "@wunderui/react"

export function ReplyActions({ answer }: { answer: string }) {
  const [feedback, setFeedback] = useState<"up" | "down" | undefined>()

  return (
    <ChatMessageActions
      feedback={feedback}
      onCopy={() => navigator.clipboard.writeText(answer)}
      onFeedback={(value) => setFeedback(feedback === value ? undefined : value)}
    />
  )
}
```

Expected result: You see four small grey icon buttons in a row: copy, regenerate, thumbs up and thumbs down. Press a thumb and it turns the link colour, and press it again to clear it.

## When to use

### Use Chat Message Actions for

- The copy, regenerate and thumbs controls under a finished assistant reply
- A rating that you send to your own feedback endpoint
- A chat that lets people ask the assistant again for the same question

### Use something else

- [Chat Message](https://wunderui.com/components/chat-message) for the bubble the actions sit under
- [Chat Loader](https://wunderui.com/components/chat-loader) for the dots shown while the reply is being regenerated
- [Toolbar](https://wunderui.com/components/toolbar) for a row of actions that belongs to a whole page or editor, with several groups

## Keyboard

The four actions are native buttons in one row, so the browser handles focus and activation. There is no arrow-key navigation, and every button is a tab stop.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the next or previous action in this order: Copy, Regenerate, Good response, Bad response. Focus shows as an indigo border with a 2 px ring. |
| `Enter` or `Space` | Presses the focused button: copies, regenerates, or sets the rating. |
| `Enter` or `Space` | On a thumb that is already pressed, the press reaches `onFeedback` with the same value again; clear the rating there to turn it off. |

## Behavior

What the row does with its handlers, its state, assistive technology and motion.

- **Handlers:** Every button calls its handler and does nothing else. All handlers are optional, and a button without one still renders and takes focus.
- **Clipboard:** The row writes nothing to the clipboard, so do it in the copy handler. The browser call rejects without permission, so catch it and say so in the status line.
- **Rating:** The feedback value is controlled: up presses Good response, down presses Bad response, anything else presses neither. A pressed thumb takes the link colour.
- **Names:** Each button has an aria-label (Copy, Regenerate, Good response, Bad response) and the same text as a title. Only the thumbs report a pressed state, since the other two are actions.
- **Live region:** The row is not a live region and its names do not change after a press. Put a status line next to it that is in the page from the start, and fill it with Copied or Could not copy.
- **States:** Hover fills the button with the page tone and darkens the icon, pressed fills it with the subtle tone, and focus is an indigo border with a 2 px ring. The icons are 14 px in a 24 px target.
- **Motion:** None. Hover, pressed and focus change colour and ring at once, and nothing moves, so there is nothing to reduce.

## Anatomy

- `ChatMessageActions`: A flex row with 2 px between its buttons. It takes handlers for copy, regenerate and feedback, and the rating already given.
- `Copy`: A 24 px icon button named Copy. It calls the copy handler and writes nothing to the clipboard itself.
- `Regenerate`: A 24 px icon button named Regenerate that calls the regenerate handler.
- `Good response`: A thumbs-up button, shown as pressed when the feedback is up. It calls the feedback handler with up.
- `Bad response`: A thumbs-down button, shown as pressed when the feedback is down. It calls the feedback handler with down.

## Best practices

### When to use

- Use ChatMessageActions under a finished assistant reply: copy it, ask again, rate it. For actions on code or a document, use the controls of the Code Block or an artifact panel.

### Do

- Show the row when the reply is complete, not while it streams. Copy and Regenerate act on the whole message.
- Write to the clipboard in the copy handler with navigator.clipboard.writeText, and catch a refusal. It fails without permission and on pages that are not secure.
- Confirm the copy in a status line next to the row that is in the page before it has text. The button keeps the name Copy, so without the line a screen reader user hears nothing.
- Hold the rating in state and hand it back as feedback, so the matching thumb stays pressed, also after a reload. Clear it when the same thumb is pressed again and when the reply is regenerated.

### Don't

- Don't pass a feedback handler without storing the value. The thumbs only mirror the feedback value and do not toggle on their own.
- Don't show the row on a user message or on a reply that failed. Offer a retry there instead.
- Don't rely on the title tooltip for the meaning of the icons. Hover is not available on touch, so the aria-label is the name.

## API reference

### ChatMessageActions

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string |  | Extra classes for the row, for example `ps-12` to line it up with a bubble that has an avatar, or `mt-2` under text. |
| defaultFeedbackOpen | boolean | false | Opens the reasons panel on first render, for a demo state or a screen that starts mid-feedback. Needs `feedbackReasons`. |
| feedback | "up" \| "down" |  | The rating already given: `up` presses Good response, `down` presses Bad response, leaving it out presses neither. |
| feedbackReasons | string[] |  |  |
| onCopy | () => void |  | Called when Copy is pressed. Write the reply to the clipboard here and confirm it; the component does neither. |
| onFeedback | (value: "up" \| "down", detail?: { reasons: string[]; details: string }) => void |  | Called with `up` or `down` when a thumb is pressed, also when it is already pressed. Store the value and hand it back as `feedback`. |
| onRegenerate | () => void |  | Called when Regenerate is pressed. Start the reply again and hide the row until it is complete. |
| onRegenerateWith | (option: string) => void |  |  |
| regenerateOptions | string[] |  |  |

## Examples

### Placement: under the bubble, in the bubble, or under a plain reply

### Copy status: idle, copied, could not copy

### Copy confirmation, feedback reasons and regenerate options

## In context

### Whole reply: the loader, the streamed text, then copy, regenerate and the rating

Press Regenerate. The row goes away, the loader shows, the words stream in and the row returns with the rating cleared, and Copy writes the answer to the clipboard.

### Timing: no actions while the reply streams

Copy and Regenerate act on the whole message, so the row waits until the reply is complete. The card keeps the row's height, so nothing jumps when it appears.

## For AI agents

`get_component("chat-message-actions")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
