Ask Rift AI
Theme: Smoke
Layout: Contained
Background: Field
Search or ask anythingAsk Rift AI
Theme: Smoke
Layout: Contained
Background: Field
Colour mode: System

Copy button

Copy a value and say so

A button that puts a value on the clipboard, then turns its glyph to a check and its label to Copied for a moment. Code blocks and description lists copy through it, so every copy in the library confirms the same way.

With text

Tertiary and compact by default, to sit quietly in a header or beside a value. tone="neutral" draws the secondary outline in the neutral greys, for a utility control such as a page's copy link.

Icon only

Copy the colourCopy the colour

An IconButton with its name in a tooltip. The name changes to Copied after a press, which a screen reader announces.

A value read at the press

Pass a function for a value that moves, such as the address of the current page.

Alternatives

  • Use Icon button instead when the button runs an action other than copying a value.

Props

Read from the same JSDoc that ships in the package's types. A required prop is marked with an asterisk.

CopyButton props
PropTypeDefaultDescription
value*
string | (() => string)
The text put on the clipboard, or a function that returns it at the moment of the press (for a value that changes, such as the current URL).
onCopied
((value: string) => void)
Called with the copied text as it is sent to the clipboard (the write is not awaited), so a host can count copies or announce them.
copyText
string
'Copy'
Visible text before a copy. When `iconOnly`, it is the accessible name and the tooltip instead, unless `copyLabel` is set.
copyLabel
string
Accessible name before a copy. Defaults to `copyText`.
copiedLabel
string
'Copied'
Visible text and accessible name for a moment after a copy.
iconOnly
boolean
false
Show only the glyph, with the label in a tooltip, as an IconButton.
tooltipPosition
"top" | "bottom" | "left" | "right" | "start" | "end"
'top'
Where the icon-only form's tooltip sits, as on IconButton.
variant
"secondary" | "tertiary"
'tertiary'
Visual emphasis, as on Button.
tone
"default" | "neutral"
'default'
Colour, as on Button: `neutral` draws the secondary outline in the neutral greys rather than the action colour, for a utility control such as a page's "Copy link".
size
"default" | "compact"
'compact'
Control size, as on Button.
disabled
boolean
false
Disable the button.
className
string
''
Additional CSS classes.

Tested keys

An automated test presses every row below, in a left-to-right and a right-to-left layout.

Copy button follows the WAI-ARIA button pattern.

Keys the Copy button is tested against
KeyWhat it does
Enter
Activates the button.
Space
Activates the button.
tsx
// From the npm package
import { CopyButton } from 'rift-ds/components/CopyButton/CopyButton';

// Or as source you own, via the shadcn CLI
npx shadcn@latest add https://rift-ds.com/r/copy-button.json

5.7 kB gzipped, with everything it imports. Peer dependencies are not counted.

For agents: the props, their allowed values and defaults, and the tested keys, as markdown or as a JSON schema.