Layout & primitives
CopyButton
Free13.2 KB gzippedA 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
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).
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".
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).
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".
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.
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
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| Prop | Type | Default |
|---|---|---|
valueRequiredThe text to copy, or a function that returns it when clicked (for values that change, such as the current URL). | string | (() => string) | — |
iconOnlyShow only the icon. The accessible name is | boolean | false |
childrenVisible label while idle. | ReactNode | "Copy" (translated) |
copiedLabelLabel shown and announced after a successful copy. | string | "Copied" (translated) |
copyErrorLabelLabel shown and announced when copying fails. | string | "Couldn't copy" (translated) |
timeoutHow long the copied or error state shows, in milliseconds. | number | 2000 |
onCopyStatusChangeCalled with each copy result, then with | (status: CopyStatus) => void | — |
variantVisual style. Inherits from a surrounding | "solid""soft""outline""ghost""link""inverse" | "solid" |
toneSemantic color. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
disabledDisables the control. Buttons use the native | boolean | false |
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)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 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
| Key | Action |
|---|---|
| EnterSpace | Copies the text. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<button> | button | Named by its label, or aria-label ("Copy" by default) with iconOnly |
| Live region | status | aria-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.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every 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) |
| Focus | Focus 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 readers | Names, 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) |
| Color | Meaning 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 reflow | At 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 targets | Click 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) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |