Skip to content

CopyButton ​

Copies text to the clipboard. The label switches to "Copied" for a few seconds and the result is announced to screen readers.

Usage ​

Basic usage ​

vue
<SuCopyButton value="npm install @surgeui/vue" variant="outline" />

Icon only ​

vue
<SuCopyButton value="sk_live_51Hx4f2a" icon-only label="Copy the key" />

With icon-only, the label stays the button name: name it after what it copies ("Copy the key", "Copy the link").

API ​

Props ​

PropTypeDefaultDescription
valuestring-Copied text
labelstring'Copy'Button name
copiedLabelstring'Copied'Label shown after copying
iconOnlybooleanfalseIcon only (the name is still read)
variant'primary' | 'secondary' | 'outline' | 'ghost''ghost'Button variant
size'sm' | 'md' | 'lg''sm'Size
timeoutnumber2000How long the "copied" state lasts (ms)

Events ​

EventPayloadDescription
copystringSuccessful copy
errorunknownCopy failed (permission denied, browser)

Accessibility ​

  • The button name does not change: a name change while focused is not read reliably.
  • The result is announced through a live region (useAnnouncer): "Copied to clipboard", or "Could not copy" (assertive).
  • The confirmation check mark is decorative; the visible label switches to "Copied".

Publié sous licence MIT.