{"slug":"response-actions","category":"messages","job":"steer","added":"2026-11-08T13:31Z","title":"Response Actions","description":"A toolbar under a finished answer — copy, rate, share and a Regenerate menu with named alternatives — where a thumbs-down asks what went wrong.","url":"https://ai-patterns.app/patterns/messages/response-actions","markdown":"https://ai-patterns.app/patterns/messages/response-actions.md","json":"https://ai-patterns.app/api/patterns/messages/response-actions","seenIn":[{"team":"chatgpt","source":"https://help.openai.com/en/articles/6825453-chatgpt-release-notes"},{"team":"Perplexity","source":"https://www.perplexity.ai/help-center/en/articles/12802813-how-do-i-change-to-my-preferred-ai-model"},{"team":"Google Gemini","source":"https://support.google.com/gemini/answer/14262426?hl=en&co=GENIE.Platform%3DDesktop"},{"team":"Claude","source":"https://support.claude.com/en/articles/8525154-claude-is-providing-incorrect-or-misleading-responses-what-s-going-on"}],"spec":"# Response Actions\n\n## Summary\nA toolbar that stays under a finished answer: Copy, thumbs up and down, Share, and a Regenerate button with a menu of ways to try again. A thumbs-down opens a short panel asking what went wrong, so the rating comes with a reason the team can act on. Regenerate goes past \"same prompt, new answer\" with named alternatives, such as a more concise version or a different model, so people can get the answer they need without rewriting the prompt.\n\n## When to use\n- Long-form answers (explanations, drafts, research) where the reply is the deliverable and people copy, share or retry it.\n- Products that collect answer-quality feedback and need reasons, not just a count of thumbs-downs.\n- When there are a few useful, nameable ways to retry: another model, a shorter answer, more sources.\n\n## When not to use\n- Busy chat threads where every message has actions — use Chat Bubble with Actions, which hides its row until hover so the thread stays calm.\n- Adjusting an answer's tone or length as an editing step — use Refinement Controls, which keeps each result as a version beside the original.\n- Answers that can't be reproduced, like a one-off tool run with side effects; \"Regenerate\" would repeat the action, not just the text.\n\n## Anatomy\n- Toolbar under the answer, aligned with its text: Copy, Good response, Bad response, Share, Regenerate.\n- Status text after the buttons: \"Copied\", \"Link copied\", \"Thanks for the feedback\".\n- Regenerate split menu: \"Try again\" first, a divider, then the named options, each with a one-line hint.\n- Feedback panel, which opens below the toolbar on a thumbs-down: a heading, reason chips (several can be picked), an optional note, a line saying what's sent, and Send (Skip when nothing is picked) and Close.\n\n## Behavior\n- The toolbar is visible at rest on the latest answer. On earlier answers it can fall back to hover or focus, as Chat Bubble with Actions does.\n- Copy copies the answer as text and swaps its icon for a check for about two seconds. Share copies a link the same way and says \"Link copied\".\n- Thumbs are a toggle pair: picking one clears the other, and picking the active one again clears the rating. The rating is recorded immediately; the reason is extra.\n- Thumbs-down opens the feedback panel; thumbs-up just says thanks. Send or Skip closes the panel and thanks the person. Close or Escape closes it and keeps the rating.\n- Regenerate opens its menu with focus on \"Try again\". Choosing an item closes the menu and starts the new answer. The button spins and reads \"Regenerating…\" until the answer arrives, and the rating resets, because it belonged to the old answer.\n- Without extra options, Regenerate is a single icon button that just tries again.\n- Keep earlier answers as versions (see Conversation Branches) rather than replacing them, so a regenerate never loses an answer someone liked.\n\n## Content guidelines\n- Name regenerate options by their result (\"More concise\", \"Try with Fast model\"), and give each a short hint about the trade-off.\n- Keep to five or six feedback reasons, each a short phrase people recognise (\"Not accurate\", \"Too long\"). Put the most common first and include a safety reason.\n- Say what feedback sends (\"Sent with this conversation to help improve answers\"), so no one shares more than they meant to.\n- Status messages are two or three words, with no exclamation marks.\n\n## Accessibility\n- The row is a `toolbar` with an accessible name; every icon button has a label and a tooltip.\n- Thumbs use `aria-pressed`; thumbs-down also sets `aria-expanded` while the feedback panel is open.\n- Regenerate is a menu button (`aria-haspopup=\"menu\"`, `aria-expanded`). Arrow keys, Home and End move through items, and Escape closes the menu and returns focus to the button.\n- Status text is in a polite live region, so \"Copied\" is announced without moving focus.\n- The feedback panel is a labelled region; reason chips are toggle buttons with `aria-pressed`.\n- Icon swaps and the panel's height animation become a plain fade when the user prefers reduced motion.\n\n## Related patterns\n- **Chat Bubble with Actions** — Use it instead in chat threads, where per-message actions should stay hidden until hover.\n- **Conversation Branches** — Defines how each regenerated answer is kept as a version people can switch between.\n- **Refinement Controls** — Use it alongside for edits to the answer itself: shorter, more formal, as bullets.\n- **Model Picker** — Use it for the conversation's model; the regenerate menu only switches the model for one retry.\n","code":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { Check, ChevronDown, Copy, Link2, RefreshCw, ThumbsDown, ThumbsUp, X } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport type ResponseRating = \"up\" | \"down\" | null;\n\nexport interface ResponseFeedback {\n  rating: Exclude<ResponseRating, null>;\n  reasons: string[];\n  note: string;\n}\n\nexport interface RegenerateOption {\n  id: string;\n  label: string;\n  /** Shown under the label, e.g. \"Faster, less detail\". */\n  hint?: string;\n}\n\nexport interface ResponseActionsProps {\n  /** The reply as plain text or Markdown, for Copy. */\n  text: string;\n  rating?: ResponseRating;\n  onRate?: (rating: ResponseRating) => void;\n  /** Called when the person sends a reason for a thumbs-down (or skips it). */\n  onFeedback?: (feedback: ResponseFeedback) => void;\n  /** Reasons offered after a thumbs-down. */\n  reasons?: string[];\n  /** Called with no option for a plain \"Try again\", or with the chosen option. */\n  onRegenerate?: (option?: RegenerateOption) => void;\n  /** Extra ways to regenerate, listed in the menu under \"Try again\". */\n  regenerateOptions?: RegenerateOption[];\n  /** True while a new version is being generated. */\n  regenerating?: boolean;\n  /** Returns a share link; Share is hidden without it. */\n  onShare?: () => string | Promise<string>;\n  className?: string;\n}\n\nconst DEFAULT_REASONS = [\"Not accurate\", \"Didn't follow instructions\", \"Too long\", \"Too vague\", \"Unsafe or offensive\"];\n\nexport function ResponseActions({\n  text,\n  rating = null,\n  onRate,\n  onFeedback,\n  reasons = DEFAULT_REASONS,\n  onRegenerate,\n  regenerateOptions = [],\n  regenerating = false,\n  onShare,\n  className,\n}: ResponseActionsProps) {\n  const [flash, setFlash] = React.useState<\"copied\" | \"linked\" | \"thanks\" | null>(null);\n  const [feedbackOpen, setFeedbackOpen] = React.useState(false);\n  const flashTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  React.useEffect(() => () => clearTimeout(flashTimer.current), []);\n\n  function showFlash(kind: NonNullable<typeof flash>) {\n    clearTimeout(flashTimer.current);\n    setFlash(kind);\n    flashTimer.current = setTimeout(() => setFlash(null), 1800);\n  }\n\n  async function copy() {\n    try {\n      await navigator.clipboard.writeText(text);\n      showFlash(\"copied\");\n    } catch {\n      // Clipboard can be blocked (permissions, insecure context); stay quiet.\n    }\n  }\n\n  async function share() {\n    if (!onShare) return;\n    try {\n      const url = await onShare();\n      await navigator.clipboard.writeText(url);\n      showFlash(\"linked\");\n    } catch {\n      // Leave the button as it was; the host can surface its own error.\n    }\n  }\n\n  function rate(next: Exclude<ResponseRating, null>) {\n    const value = rating === next ? null : next;\n    onRate?.(value);\n    if (value === \"down\") setFeedbackOpen(true);\n    else {\n      setFeedbackOpen(false);\n      if (value === \"up\") showFlash(\"thanks\");\n    }\n  }\n\n  const status =\n    flash === \"copied\" ? \"Copied\" : flash === \"linked\" ? \"Link copied\" : flash === \"thanks\" ? \"Thanks for the feedback\" : \"\";\n\n  return (\n    <div className={cn(\"flex flex-col gap-2\", className)}>\n      <div role=\"toolbar\" aria-label=\"Response actions\" className=\"flex items-center gap-0.5 text-muted-foreground\">\n        <IconAction label={flash === \"copied\" ? \"Copied\" : \"Copy\"} onClick={copy}>\n          <SwapIcon active={flash === \"copied\"} on={<Check />} off={<Copy />} />\n        </IconAction>\n\n        {onRate && (\n          <>\n            <IconAction label=\"Good response\" pressed={rating === \"up\"} onClick={() => rate(\"up\")}>\n              <ThumbsUp className={cn(rating === \"up\" && \"fill-current\")} />\n            </IconAction>\n            <IconAction\n              label=\"Bad response\"\n              pressed={rating === \"down\"}\n              expanded={feedbackOpen}\n              onClick={() => rate(\"down\")}\n            >\n              <ThumbsDown className={cn(rating === \"down\" && \"fill-current\")} />\n            </IconAction>\n          </>\n        )}\n\n        {onShare && (\n          <IconAction label={flash === \"linked\" ? \"Link copied\" : \"Copy share link\"} onClick={share}>\n            <SwapIcon active={flash === \"linked\"} on={<Check />} off={<Link2 />} />\n          </IconAction>\n        )}\n\n        {onRegenerate && (\n          <RegenerateButton options={regenerateOptions} busy={regenerating} onRegenerate={onRegenerate} />\n        )}\n\n        <span aria-live=\"polite\" className=\"ml-1.5 text-xs\">\n          <AnimatePresence mode=\"wait\">\n            {status && (\n              <motion.span\n                key={status}\n                initial={{ opacity: 0, x: -4 }}\n                animate={{ opacity: 1, x: 0 }}\n                exit={{ opacity: 0 }}\n                transition={{ duration: 0.15 }}\n              >\n                {status}\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </span>\n      </div>\n\n      <AnimatePresence initial={false}>\n        {feedbackOpen && (\n          <FeedbackPanel\n            reasons={reasons}\n            onClose={() => setFeedbackOpen(false)}\n            onSend={(picked, note) => {\n              onFeedback?.({ rating: \"down\", reasons: picked, note });\n              setFeedbackOpen(false);\n              showFlash(\"thanks\");\n            }}\n          />\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nfunction IconAction({\n  label,\n  pressed,\n  expanded,\n  onClick,\n  children,\n}: {\n  label: string;\n  pressed?: boolean;\n  expanded?: boolean;\n  onClick: () => void;\n  children: React.ReactNode;\n}) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      title={label}\n      aria-pressed={pressed}\n      aria-expanded={expanded}\n      onClick={onClick}\n      className={cn(\n        \"flex size-8 items-center justify-center rounded-md transition-colors hover:bg-accent hover:text-foreground [&_svg]:size-4\",\n        pressed && \"text-foreground\"\n      )}\n    >\n      {children}\n    </button>\n  );\n}\n\n/** Cross-fades between two icons, e.g. Copy → Check. */\nfunction SwapIcon({ active, on, off }: { active: boolean; on: React.ReactNode; off: React.ReactNode }) {\n  const reduceMotion = useReducedMotion();\n  return (\n    <AnimatePresence mode=\"popLayout\" initial={false}>\n      <motion.span\n        key={active ? \"on\" : \"off\"}\n        initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6 }}\n        animate={{ opacity: 1, scale: 1 }}\n        exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6 }}\n        transition={{ duration: 0.15 }}\n        className=\"flex\"\n        aria-hidden\n      >\n        {active ? on : off}\n      </motion.span>\n    </AnimatePresence>\n  );\n}\n\nfunction RegenerateButton({\n  options,\n  busy,\n  onRegenerate,\n}: {\n  options: RegenerateOption[];\n  busy: boolean;\n  onRegenerate: (option?: RegenerateOption) => void;\n}) {\n  const [open, setOpen] = React.useState(false);\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const itemsRef = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const menuId = React.useId();\n  const reduceMotion = useReducedMotion();\n\n  React.useEffect(() => {\n    if (!open) return;\n    itemsRef.current[0]?.focus();\n    function onPointerDown(e: PointerEvent) {\n      if (!wrapRef.current?.contains(e.target as Node)) setOpen(false);\n    }\n    document.addEventListener(\"pointerdown\", onPointerDown);\n    return () => document.removeEventListener(\"pointerdown\", onPointerDown);\n  }, [open]);\n\n  function close() {\n    setOpen(false);\n    triggerRef.current?.focus();\n  }\n\n  function pick(option?: RegenerateOption) {\n    setOpen(false);\n    onRegenerate(option);\n  }\n\n  function onMenuKeyDown(e: React.KeyboardEvent) {\n    const items = itemsRef.current.filter(Boolean) as HTMLButtonElement[];\n    const index = items.indexOf(document.activeElement as HTMLButtonElement);\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      const step = e.key === \"ArrowDown\" ? 1 : -1;\n      items[(index + step + items.length) % items.length]?.focus();\n    } else if (e.key === \"Home\" || e.key === \"End\") {\n      e.preventDefault();\n      items[e.key === \"Home\" ? 0 : items.length - 1]?.focus();\n    } else if (e.key === \"Escape\" || e.key === \"Tab\") {\n      if (e.key === \"Escape\") e.preventDefault();\n      close();\n    }\n  }\n\n  const icon = (\n    <motion.span\n      className=\"flex\"\n      animate={busy && !reduceMotion ? { rotate: 360 } : { rotate: 0 }}\n      transition={busy ? { duration: 0.9, repeat: Infinity, ease: \"linear\" } : { duration: 0.2 }}\n      aria-hidden\n    >\n      <RefreshCw className=\"size-4\" />\n    </motion.span>\n  );\n\n  if (!options.length) {\n    return (\n      <IconAction label={busy ? \"Regenerating\" : \"Regenerate\"} onClick={() => !busy && onRegenerate()}>\n        {icon}\n      </IconAction>\n    );\n  }\n\n  return (\n    <div ref={wrapRef} className=\"relative\">\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        aria-haspopup=\"menu\"\n        aria-expanded={open}\n        aria-controls={open ? menuId : undefined}\n        aria-busy={busy}\n        disabled={busy}\n        onClick={() => setOpen((v) => !v)}\n        onKeyDown={(e) => {\n          if (e.key === \"ArrowDown\") {\n            e.preventDefault();\n            setOpen(true);\n          }\n        }}\n        className=\"flex h-8 items-center gap-1 rounded-md px-2 text-xs font-medium transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none\"\n      >\n        {icon}\n        {busy ? \"Regenerating…\" : \"Regenerate\"}\n        <ChevronDown className={cn(\"size-3.5 transition-transform\", open && \"rotate-180\")} aria-hidden />\n      </button>\n\n      <AnimatePresence>\n        {open && (\n          <motion.div\n            id={menuId}\n            role=\"menu\"\n            aria-label=\"Regenerate\"\n            onKeyDown={onMenuKeyDown}\n            initial={{ opacity: 0, y: -4, scale: 0.98 }}\n            animate={{ opacity: 1, y: 0, scale: 1 }}\n            exit={{ opacity: 0, y: -4, scale: 0.98 }}\n            transition={{ duration: 0.12 }}\n            className=\"absolute top-full left-0 z-20 mt-1 w-56 origin-top-left rounded-2xl bg-popover p-1 text-popover-foreground border\"\n          >\n            <MenuItem ref={(el) => { itemsRef.current[0] = el; }} label=\"Try again\" hint=\"Same prompt, new answer\" onSelect={() => pick()} />\n            <div role=\"separator\" className=\"my-1 h-px bg-border\" />\n            {options.map((option, i) => (\n              <MenuItem\n                key={option.id}\n                ref={(el) => { itemsRef.current[i + 1] = el; }}\n                label={option.label}\n                hint={option.hint}\n                onSelect={() => pick(option)}\n              />\n            ))}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nfunction MenuItem({\n  ref,\n  label,\n  hint,\n  onSelect,\n}: {\n  ref: React.Ref<HTMLButtonElement>;\n  label: string;\n  hint?: string;\n  onSelect: () => void;\n}) {\n  return (\n    <button\n      ref={ref}\n      type=\"button\"\n      role=\"menuitem\"\n      tabIndex={-1}\n      onClick={onSelect}\n      className=\"flex w-full flex-col items-start rounded-lg px-2.5 py-1.5 text-left text-sm outline-none hover:bg-accent focus-visible:bg-accent\"\n    >\n      <span>{label}</span>\n      {hint && <span className=\"text-xs text-muted-foreground\">{hint}</span>}\n    </button>\n  );\n}\n\nfunction FeedbackPanel({\n  reasons,\n  onSend,\n  onClose,\n}: {\n  reasons: string[];\n  onSend: (reasons: string[], note: string) => void;\n  onClose: () => void;\n}) {\n  const [picked, setPicked] = React.useState<string[]>([]);\n  const [note, setNote] = React.useState(\"\");\n  const headingId = React.useId();\n  const reduceMotion = useReducedMotion();\n\n  return (\n    <motion.section\n      aria-labelledby={headingId}\n      initial={reduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}\n      animate={reduceMotion ? { opacity: 1 } : { opacity: 1, height: \"auto\" }}\n      exit={reduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}\n      transition={{ duration: 0.2, ease: \"easeOut\" }}\n      className=\"overflow-hidden\"\n      onKeyDown={(e) => {\n        if (e.key === \"Escape\") onClose();\n      }}\n    >\n      <div className=\"flex flex-col gap-3 rounded-2xl bg-card p-3 border\">\n        <div className=\"flex items-center justify-between gap-2\">\n          <h3 id={headingId} className=\"text-sm font-medium\">\n            What went wrong?\n          </h3>\n          <button\n            type=\"button\"\n            aria-label=\"Close\"\n            onClick={onClose}\n            className=\"flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground\"\n          >\n            <X className=\"size-3.5\" aria-hidden />\n          </button>\n        </div>\n\n        <div role=\"group\" aria-label=\"Reasons\" className=\"flex flex-wrap gap-1.5\">\n          {reasons.map((reason) => {\n            const on = picked.includes(reason);\n            return (\n              <button\n                key={reason}\n                type=\"button\"\n                aria-pressed={on}\n                onClick={() => setPicked((p) => (on ? p.filter((r) => r !== reason) : [...p, reason]))}\n                className={cn(\n                  \"rounded-full px-2.5 py-1 text-xs transition-colors bg-muted\",\n                  on ? \"bg-foreground text-background\" : \"hover:bg-foreground/10\"\n                )}\n              >\n                {reason}\n              </button>\n            );\n          })}\n        </div>\n\n        <textarea\n          value={note}\n          onChange={(e) => setNote(e.target.value)}\n          rows={2}\n          aria-label=\"Anything else? (optional)\"\n          placeholder=\"Anything else? (optional)\"\n          className=\"resize-none rounded-xl px-3 py-2 text-sm outline-none placeholder:text-muted-foreground focus:ring-1 focus:ring-foreground/30 bg-muted focus:bg-background\"\n        />\n\n        <div className=\"flex items-center justify-between gap-2\">\n          <p className=\"text-xs text-muted-foreground\">Sent with this conversation to help improve answers.</p>\n          <button\n            type=\"button\"\n            onClick={() => onSend(picked, note.trim())}\n            className=\"shrink-0 rounded-full bg-foreground px-3 py-1 text-xs font-medium text-background\"\n          >\n            {picked.length || note.trim() ? \"Send\" : \"Skip\"}\n          </button>\n        </div>\n      </div>\n    </motion.section>\n  );\n}\n","dependencies":["lucide-react","motion"],"localImports":["@/lib/utils"]}