Actions
CopyButton
Copies a text to the clipboard and confirms it visibly and for screen readers.
- Experimental
- Keyboard tested
- Screen reader not tested yet
Playground
Change the props. The controls come from the documented props.
<CopyButton text="text-secondary" label="Copy utility" />Usage
When to use
Use a copy button next to text people will paste somewhere else: code, a token name, a link, an ID.
When not to use
- For text people only read.
- As a general action button: it does exactly one thing.
How it works
A click copies the text to the clipboard. The label changes to “Copied” for a moment and a live region announces it, so the confirmation is visible and audible.
Content guidelines
Name what is copied when there is more than one button on the page: “Copy code”, “Copy class”. A lone “Copy” is enough only when nothing else could be meant.
Do and don’t
Do
- Name what is copied when there are several buttons, e.g. “Copy code”.
Don’t
- Don't copy without a visible confirmation.
Anatomy
The parts of the component and what each one does, as in the playground above.
- iconCopy icon, a check after copying.
- labelChanges to copiedLabel for two seconds.
Examples
Type-checked, and the same code goes into the AI manifest. Import: import { CopyButton } from "@/ds";
Copy a token
Props
Checked against the component's TypeScript type on every build.
| Name | Type | Default | Description |
|---|---|---|---|
| text (required) | string | – | Text that goes to the clipboard. |
| label | string | "Copy" | Label before copying. |
| copiedLabel | string | "Copied" | Label and announcement after copying. |
| variant | "primary" | "accent" | "secondary" | "ghost" | "ghost" | Button variant. |
| size | "sm" | "md" | "sm" | Button size. |
Tokens used
Derived from the utility classes in the component's source. Copy a class with one click.
| Token | Tier | Value | Utility |
|---|---|---|---|
| spacing.4 | semantic | 16px | |
| text.secondary | semantic | #555555 |
Accessibility
What is checked automatically on every build, and what a person has tested. Nothing is marked as tested unless it was.
| Check | How | Status |
|---|---|---|
| axe-core rules | Automated on every npm run check, at desktop and mobile width | Runs on every build |
| Keyboard | Automated Playwright test (scripts/keyboard.mjs) | Tested |
| Screen reader | Manual | Not tested yet |
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Copies the text. |
Semantics and focus
- The result is announced through a role="status" live region.