ord_8HcK2v- Add the registry
- Add copy-button
Usage
Give it an aria-label that says what it copies. Its Tooltip shows the same
text. After copying, the button shows a check and "Copied", and announces the result to screen
readers.
When the text is expensive to build, such as a large document serialized as JSON, or has to load
first, pass value a function that returns the text or a promise of it. The function runs only when
the button is pressed.
Examples
Text that loads first
Here value is a function that creates an invite link when the button is pressed. While its
promise loads, the button is disabled but keeps focus, and has data-pending. If it takes longer
than a second, screen readers announce "Loading". Change that with pendingAnnouncement.
Your own copy control
To copy from a control of your own, use useCopyToClipboard, the hook
behind Copy Button. It reports whether the copy worked, and takes the same resetAfter and onCopy
as Copy Button.
Props
CopyButton takes the props of a Button except onClick and children.