Skip to content

CopyButton

Icon button that copies a value to the clipboard and announces the result.

<CopyButton onCopy={fn()} value="sk_live_51ABC123" />
<CopyButton onCopy={fn()} value={() => 'value resolved when clicked'} />
<CopyButton
onCopy={fn()}
value="sk_live_51ABC123"
copiedLabel="API key copied"
copyLabel="Copy API key"
errorMessage="Could not copy API key"
/>
<HStack gap={3}>
<CopyButton {...args} />
<CopyButton {...args} isDisabled />
</HStack>

Icon button that copies a value to the clipboard and announces the result.

PropTypeDefaultDescription
copiedLabelstring'Copied'Label and tooltip shown after a successful copy.
copyLabelstring'Copy'Label and tooltip shown when the button is ready to copy.
errorMessagestring'Copy failed'Message announced assertively when copying fails.
onCopy() => void—Called after the value is successfully copied.
onCopyError(error: unknown) => void—Called when resolving the value or writing to the clipboard fails.
resetTimeoutnumber2000Time in milliseconds before the copied state resets.
value*string | (() => string)—Text to copy, or a synchronous getter evaluated on each activation.
formstring—HTML form attribute associating the button with a <form> by ID.
idstring—HTML id attribute applied to the root element.
aria-controlsstring—Identifies the element(s) whose contents are controlled by the button.
aria-describedbystring—Identifies the element(s) that describe the button.
aria-detailsstring—Identifies the element that provides a detailed description.
aria-expandedboolean—Indicates whether a controlled element is expanded or collapsed.
aria-haspopupboolean | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog'—Indicates the button opens an interactive popup element.
aria-keyshortcutsstring—Keyboard shortcuts that activate or focus the button.
aria-labelledbystring—Identifies the element(s) that label the button.
onFocusFocusEventHandler<HTMLElement>—Focus event handler for the root element.
onKeyDown(event: KeyboardEvent<HTMLElement>) => void—Keyboard event handler for the root element.
onPointerEnterPointerEventHandler<HTMLElement>—Pointer enter event handler for the root element.
styleCSSProperties—Inline styles applied to the root element.
refRef<HTMLElement>—Ref forwarded to the root element.
classNamestring—Additional CSS class names applied to the root element.
data-testidstring—Test ID applied to the root element.
isDisabledboolean—Whether the button is disabled. Prevents interaction and applies disabled styling.
size"sm" | "md" | "lg"—Visual size of the button.
variant"destructive" | "primary" | "ghost" | "onSolid" | "outline" | "secondary"—Visual style variant.