Skip to content
Mosaic
On this page

CopyButton

An icon Button that copies value to the clipboard and confirms with a short "Copied" toast beside it. Takes every Button prop but children.

Use for

  • copying an id, key, secret or URL to the clipboard
  • a copy icon next to a value

Practices

GuidancePractice
DoPass localized label and copiedLabel.
DoPass onCopyError to tell the user when the clipboard is blocked. Nothing shows otherwise.
Don’tCall preventDefault in onClick unless you mean to skip the copy.

API reference

CopyButton

A type="button" icon button. The toast carries cl-copy-button-toast and its title cl-copy-button-toast-title.

Slot: cl-button

PropTypeDescription
valuestringThe text to copy.
labelstringAccessible name of the button.Default: 'Copy'
copiedLabelstringThe toast text after a copy.Default: 'Copied'
sideToastSideSide of the button the toast shows on.Default: 'top'
resetAfternumberHow long the toast stays, in ms.Default: 2000
onCopy(value: string) => void | Promise<void>Replaces the clipboard write. Reject to show no toast.
onCopyError(error: unknown) => voidCalled when the copy fails.
color'primary' | 'neutral' | 'negative'The Button color.Default: 'neutral'
variant'filled' | 'outline' | 'ghost' | 'link'The Button variant.Default: 'ghost'
size'xs' | 'sm' | 'md' | 'lg'The Button size.Default: 'xs'
shape'default' | 'square' | 'circle'The Button shape.Default: 'square'

Examples

Copy an id

TSX
<CopyButton value={user.id} label={m.copyId} copiedLabel={m.copied} />