CopyToClipboard
Copy any string to the user's clipboard on click
Buttons
Wrap a button and use the onCopy
render prop for the button's onClick
handler.
Editable example
Menu items
When using with an OptionMenu
make sure to also use closeOnClick={false}
on the menu item to allow the user to see the copied tooltip.
Editable example
Custom tooltips
Set custom tooltip content or props using the tooltip
and tooltipOnCopied
props.
Editable example
Only show tooltip on copy
Use this when the label of the button only says "Copy", making it redundant to show a tooltip with the same label on hover.
Editable example
Accessibility
Always pass onCopy
to a <button>
element or a component that renders a <button>
element so that the action is accessible using only the keyboard.