Copy Confirm

Shows exactly what was copied and flags stray spaces or hidden characters, so the wrong thing isn't pasted somewhere important.

StopsPasted the wrong thing from the clipboard

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/copy-confirm.json

The files land in your project. They're yours to edit.

Usage

copy-confirm-usage.tsx
import { CopyConfirm } from "@/components/ui/copy-confirm"

<CopyConfirm value={row.value} label={`Copy ${row.label}`} />

What it catches

  • Copying an empty value
  • Leading or trailing whitespace and invisible characters, with a clean copy
  • Formatted numbers (grouping, currency) copied when plain digits were needed

Props

CopyConfirm props
PropTypeDefault
value* (required)

The exact value to copy.

string—
label

Accessible name when the button has no visible text, e.g. "Copy account number".

string"Copy"
toPlain

How to turn a formatted value into plain text. Defaults to stripping number formatting.

(value: string) => stringtoPlainText
previewLength

Longest preview before it is truncated in the middle.

number32
onCopy

Called with the text that actually landed on the clipboard.

(text: string) => void—
copiedLabel

Heading of the confirmation.

string"Copied"
emptyLabel

Shown instead of copying an empty value.

string"Nothing to copy. The value is empty."
blockedLabel

Shown when the browser blocks clipboard access.

string"Couldn't copy. Your browser blocked clipboard access."
cleanLabel

Button that re-copies without stray whitespace or invisible characters.

string"Copy cleaned"
plainLabel

Toggle that switches between plain and formatted copy.

string"Copy as plain text"
asPlainLabel

Note beside "Copied" when the plain version was copied.

string"as plain text"
includesLabel

Lead-in to the list of problems, e.g. "Includes 1 trailing whitespace".

string"Includes"

* required. Also accepts the native props of <button> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Icon-only button gets an aria-label; it is described by the feedback while open
  • Feedback is aria-live="polite"; Escape closes it
  • Icons are aria-hidden; the copied text is shown in a <code> element

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Can't see what the user pastes afterwards or where
  • Clipboard access can fail or be blocked by the browser; the failure is shown

What it stops

Pasted the wrong thing from the clipboard

Also known as

copy to clipboard · copy button · clipboard · whitespace · invisible characters · toast · copied · paste

Field type

Dependencies

Pairs well with