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() => voidCalled after the value is successfully copied.
onCopyError(error: unknown) => voidCalled 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.
formstringHTML form attribute associating the button with a <form> by ID.
idstringHTML id attribute applied to the root element.
aria-controlsstringIdentifies the element(s) whose contents are controlled by the button.
aria-describedbystringIdentifies the element(s) that describe the button.
aria-detailsstringIdentifies the element that provides a detailed description.
aria-expandedbooleanIndicates whether a controlled element is expanded or collapsed.
aria-haspopupboolean | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog'Indicates the button opens an interactive popup element.
aria-keyshortcutsstringKeyboard shortcuts that activate or focus the button.
aria-labelledbystringIdentifies the element(s) that label the button.
onFocusFocusEventHandler<HTMLElement>Focus event handler for the root element.
onKeyDown(event: KeyboardEvent<HTMLElement>) => voidKeyboard event handler for the root element.
styleCSSPropertiesInline styles applied to the root element.
refRef<HTMLElement>Ref forwarded to the root element.
classNamestringAdditional CSS class names applied to the root element.
data-testidstringTest ID applied to the root element.
isDisabledbooleanWhether the button is disabled. Prevents interaction and applies disabled styling.
size"sm" | "md" | "lg"Visual size of the button.
variant"destructive" | "primary" | "ghost" | "onSolid" | "secondary"Visual style variant.