Skip to contentKino
Skip to Content

Copy button

A Button that copies a value. Its icon rolls to a tick and its label to “Copied”, a screen reader hears it, and it goes back after two seconds.

npx shadcn add https://kinoui.com/r/copy-button.json
Share on

Examples

Share “Q4 field study”

Anyone at Kino with the link can read and comment.
  • AOAmara OkaforOwner
  • KWKenji WatanabeCan comment
kinoui.com/s/q4-field-study

Default

Give it the value and a label. Its icon rolls to a tick and the label to “Copied”, then both go back.

KN-1284

Icon only

An icon size takes an aria-label, which its tooltip shows; after a press the tooltip says how the copy went.

Keep it secret: it can read every note.

In a field

Put it in an InputGroupAddon, at the size of the field’s buttons.

npm install @kino/sdk

In a code block

A function for value is read at the press, so it copies the text on the page as it is then.

Kino 2.4

What changed in the last three weeks.
  • 12 NovNotes open offline and sync when you’re back.
  • 6 NovShare a study with a link that expires.
  • 29 OctExport any note as Markdown or PDF.

Async value

A function may return a promise, for text it fetches at the press. A wait past 200ms shows the spinner.

KW
Kenji Watanabe

The checkout copy reads well. Can we ship it with Thursday’s build?

Render

Pass another button with render, such as a ToolbarButton, and it copies the same way.

Installation

npx shadcn@latest add https://kinoui.com/r/copy-button.json
Files
lib/refs.tslib/reduce-motion.tslib/resize.tslib/swap.tsxcomponents/kino/spinner.tsxcomponents/kino/button.tsxlib/popup.tslib/glide.tsxcomponents/kino/tooltip.tsxlib/announce.tsxcomponents/kino/copy-button.tsx
Packages
@base-ui/reactclass-variance-authority

New to Kino? Installation covers what your project needs first and the @kino namespace.

API reference

Props

PropTypeDefaultDescription
valuestring() => string() => Promise<string>NoneWhat goes on the clipboard. A function is read at the press; one that throws or rejects is a failed copy.
childrenReactNode'Copy'The label, for a size that isn’t an icon size.
aria-labelstring'Copy'An icon size’s name, which its tooltip shows. Name what it copies, such as “Copy API key”.
iconReactNodeNoneThe icon at rest, in place of the copy icon, such as a link.
copiedLabelstring'Copied'What the label, the tooltip and the screen reader say once it has copied.
failedLabelstring'Couldn’t copy'What they say when the browser refuses.
timeoutnumber2000How long the result shows, in ms. A press meanwhile copies again and starts it over; Infinity keeps it.
renderReactElementNoneThe button to render in place of the Button, such as a ToolbarButton or a SplitButtonAction. Its own props win, so a Split button’s action keeps the group’s variant unless you pass one.
tooltipPropsTooltipContentPropsNoneGo to an icon size’s TooltipContent, such as side.

Data attributes

AttributeOnDescription
data-copiedCopyButtonPresent while it shows that it copied.
data-failedCopyButtonPresent while it shows that the copy failed.

Accessibility

  • A polite status region beside the button says “Copied” or “Couldn’t copy”, and says it again on the next press.
  • An icon-only button keeps its name, such as “Copy API key”, so it reads the same each time; its tooltip shows the name to everyone else.
  • Focus stays on the button, and while a fetched value is on its way the button is busy and takes no second press.
  • A failure shows an alert icon and words, not a colour alone.
  • Where the browser refuses the Clipboard API, as on plain http or in an iframe without clipboard-write, it copies through a hidden selection instead, and puts focus back.