Skip to main content
  1. Docs
  2. Components
  3. Actions

Copy button

Copies a value. The icon turns to a check, "Copied" is announced, and focus stays.

Import
@qeetrix/react/experimental
Status
ExperimentalSince 0.0.4
Renders
<button>Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

copy-button.tsx
// Experimental: from the package's experimental entry, until it's stable.
import { CopyButton } from "@qeetrix/react/experimental";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
valuestring | () => string | Promise<string>requiredThe text, or a function that makes it, even asynchronously.
labelstring"Copy"What it copies: its name and its tooltip.
childrenReactNode—A visible label: then it's a Button, label first.
variant"ghost" | "soft" | "solid""ghost"As Icon button's.
tone"brand" | "danger" | "neutral""neutral"Neutral for a utility, as most are.
size"sm" | "md" | "lg""md"Height from the density tokens.
tooltipSide"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end""top"The side its tooltip opens on.
onCopied(value: string) => void—Called once the text is on the clipboard.
onCopyError(error: unknown) => void—Called when copying fails, e.g. with no clipboard access.
resetAfternumber2000How long "Copied" shows, in milliseconds.
messagesPartial<{ copy, copied, failed }>—This button's words, over QeetrixProvider's.
disabledbooleanfalseSets aria-disabled; it stays focusable.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
icon-button<button>The root, icon-only. data-state: idle, copied or failed. button with a label.
button-icon<svg>Copy, check or alert.
—<span role="status">Visually hidden: announces "Copied" or "Couldn't copy".

04

A value made when it's copied

A function, even async: fetched or made at the moment of the copy.

invite.tsx
<CopyButton
  value={async () => (await createInvite({ role: "member" })).url}
  label="Copy an invite link"
  onCopied={() => track("invite_copied")}
>
  Copy invite link
</CopyButton>

05

In another language

Its words come from QeetrixProvider; messages overrides one button's.

hindi.tsx
import { QeetrixProvider } from "@qeetrix/react";
import { CopyButton } from "@qeetrix/react/experimental";
import { hi } from "@qeetrix/react/locales/hi";

<QeetrixProvider locale="hi-IN" messages={hi}>
  <CopyButton value="usr_01J8K2M4PQ" />
</QeetrixProvider>
Next — Copy buttonAccessibility