CopyButton

A copy button that briefly shows the copied text above itself, so you see exactly what landed on the clipboard.

Preview

Props

Install

npx shadcn@latest add @evilbuttons/copy-button

Usage

import { CopyButton } from "@/components/evil-buttons/copy-button";

export function ButtonDemo() {
  return (
    <CopyButton
      value="npm install evil-buttons"
      onCopy={(text) => console.log("Copied", text)}
    />
  );
}

Variants

Custom labels

Name the action after what it copies.

Secret value

Turn off showValue when the text shouldn't be flashed on screen, like an API key.

Props

The component spreads native button props except value and onCopy, and forwards its ref to the button.

PropTypeDefaultDescription
valuestring-Text written to the clipboard. Required.
timeoutnumber1500Milliseconds before the button returns to idle.
copyLabelReact.ReactNode"Copy"Label shown before copying.
copiedLabelReact.ReactNode"Copied"Label shown after a successful copy.
errorLabelReact.ReactNode"Failed"Label shown when the clipboard write fails.
showValuebooleantrueShow the copied text in a small chip above the button after copying.
onCopy(value: string) => void-Fired with the copied text after a successful write.
classNamestring-Extra classes passed to the button.

Good to know

  • Falls back to execCommand on plain HTTP.
  • Never changes width between states.
  • Announces copy success or failure to screen readers.

Search docs

Jump to a button documentation page