Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Layout & primitives

CopyButton

Free13.2 KB gzipped

A button that copies text to the clipboard and confirms it: the icon turns into a check and the label into "Copied", and the result is announced to screen readers through a polite live region (a label change on a focused button isn't reliably read). Falls back to a legacy copy method where the Clipboard API is blocked, and shows an error state if both fail.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Enter, Space · Full report

Import

tsx
import { CopyButton } from "@vjdesigns/vjdesigns-ui";

Importing only CopyButton adds about 13.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Basic

Copies value and confirms it: the icon turns into a check and the label into "Copied" for 2 seconds (timeout).

tsx
import { CopyButton } from "@vjdesigns/vjdesigns-ui";

export function Basic() {
  return <CopyButton value="npm install @vjdesigns/vjdesigns-ui" />;
}

Icon only

iconOnly shows just the icon. Give it an aria-label that says what it copies; without one, it's named "Copy".

tsx
import { CopyButton, Flex, Input } from "@vjdesigns/vjdesigns-ui";

export function IconOnly() {
  return (
    <Flex gap={2} align="center" style={{ width: "100%", maxWidth: "28rem" }}>
      <Input aria-label="Invite link" readOnly value="https://example.com/join/8f3k2" style={{ flex: 1 }} />
      <CopyButton value="https://example.com/join/8f3k2" iconOnly aria-label="Copy invite link" />
    </Flex>
  );
}

Variants

Takes Button's variant, tone and size, your own labels, and a function for value when the text changes (it runs on click).

tsx
import { CopyButton, Flex, Stack } from "@vjdesigns/vjdesigns-ui";

export function Variants() {
  return (
    <Stack gap={3} align="start">
      <Flex gap={2} wrap="wrap" align="center">
        <CopyButton value="VJ-2048" variant="soft" />
        <CopyButton value="VJ-2048" variant="outline" size="sm" />
        <CopyButton value="VJ-2048" variant="solid" tone="primary" size="lg" />
      </Flex>
      <CopyButton value={() => window.location.href} copiedLabel="Link copied">
        Copy page link
      </CopyButton>
    </Stack>
  );
}

Accessibility

The result is announced through a polite live region, since a label change on a focused button isn't reliably read. If the clipboard is blocked, the button shows an error state and announces "Couldn't copy".

tsx
import { CopyButton } from "@vjdesigns/vjdesigns-ui";

export function Accessibility() {
  return <CopyButton value="coach@example.com" copiedLabel="Email address copied" />;
}

Translated

The labels come from the locale. Here in French.

tsx
import { CopyButton, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import fr from "@vjdesigns/vjdesigns-ui/locales/fr";

export function Translated() {
  return (
    <LocaleProvider locale="fr" messages={fr}>
      <CopyButton value="Bonjour" />
    </LocaleProvider>
  );
}

Right to left

The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.

Basic

tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
  <Basic />
</LocaleProvider>

Usage notes

Takes Button's style props (variant, tone, size, radius) and any native <button> attribute. An onClick that calls preventDefault() cancels the copy.

API reference

CopyButton

New in 3.5.1
CopyButton props
PropTypeDefault
valueRequired

The text to copy, or a function that returns it when clicked (for values that change, such as the current URL).

string | (() => string)—
iconOnly

Show only the icon. The accessible name is aria-label if you pass one (e.g. "Copy invite link"), otherwise the translated "Copy".

booleanfalse
children

Visible label while idle.

ReactNode"Copy" (translated)
copiedLabel

Label shown and announced after a successful copy.

string"Copied" (translated)
copyErrorLabel

Label shown and announced when copying fails.

string"Couldn't copy" (translated)
timeout

How long the copied or error state shows, in milliseconds.

number2000
onCopyStatusChange

Called with each copy result, then with "idle" when it resets.

(status: CopyStatus) => void—
variant

Visual style. Inherits from a surrounding ButtonGroup.

"solid""soft""outline""ghost""link""inverse""solid"
tone

Semantic color. Inherits from a surrounding ButtonGroup.

"neutral""primary""accent""success""warning""danger""info""primary"
size

Control height, padding, and type size. Inherits from a surrounding ButtonGroup.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --control-radius (pill).

"none""xs""sm""md""lg""xl""2xl""pill""pill"
disabled

Disables the control. Buttons use the native disabled attribute; links drop href and get aria-disabled.

booleanfalse

Also accepts native <button> attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

CopyButton targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

36 passed · 0 failed · 29 not applicable · 10 to check by hand

Dark mode

Score 100

36 passed · 0 failed · 29 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
EnterSpaceCopies the text.

Roles and states

Roles and states
ElementRoleStates and properties
<button>buttonNamed by its label, or aria-label ("Copy" by default) with iconOnly
Live regionstatusaria-live="polite"; announces "Copied" or "Couldn't copy"

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)