For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /dolan/copy-button.md.

Copy Button

A button that copies text to the clipboard, such as an invite code or a link, then says it did.

Installation

npx @blotch/dolan add copy-button
import { UiCopyButton } from '../components/ui/copy-button';

This also adds Button, which it draws, and Icon.

Usage

src/app/app.ts
import { Component, input } from '@angular/core';
import { UiCopyButton } from '../components/ui/copy-button';

@Component({
  selector: 'app-referral-code',
  imports: [UiCopyButton],
  template: `
    <ui-copy-button [value]="code()" variant="outline">
      Copy invite code
    </ui-copy-button>
  `,
})
export class ReferralCode {
  readonly code = input.required<string>();
}
  • A tap copies value with LynxClipboard.
  • For two seconds, it says "Copied" with a check icon, and a screen reader announces it.
  • Android 13 and later show every copy themselves, in a panel at the bottom of the screen that TalkBack reads. There the button stays as it is, so the copy isn't announced twice.

Variants and sizes

It takes Button's variant and size:

<ui-copy-button [value]="link()" variant="secondary" size="sm">
  Copy link
</ui-copy-button>

A class places and sizes it, such as class="w-full" for a full-width button.

Icon only

<ui-copy-button
  [value]="code()"
  variant="ghost"
  size="icon"
  accessibility-label="Copy invite code"
/>

With size="icon", it shows only its icon. Give it an accessibility-label for a screen reader to say. While the button shows the check, the label says "Copied" instead.

When it can't copy

<ui-copy-button [value]="code()" (copyFailed)="showError($event)">
  Copy code
</ui-copy-button>

copyFailed emits the ClipboardError, and the button says nothing. Lynx Explorer has no clipboard, so a copy there always fails. Run the app's own build instead (ng build --platform ios|android).

API

InputTypeDefaultDescription
valuestringrequiredThe text it copies.
variantButtonVariant'default'Visual style, as Button's.
size'default' | 'sm' | 'lg' | 'icon' | 'icon-circle''default'Height and padding, as Button's. The icon sizes show the icon.
disabledbooleanfalseDims the button, which then doesn't copy.
copiedLabelstring'Copied'What it says after it copies, and the screen reader announces.
durationnumber2000How long it says so, in milliseconds.
accessibility-labelstring—What a screen reader says. Needed for an icon-only button.
classstring''Extra Tailwind classes for the box the button fills.
OutputTypeDescription
copiedstringEmits the text once it's on the clipboard.
copyFailedClipboardErrorEmits why it couldn't copy.

Accessibility

  • A screen reader reads it as a button, with its label, or its accessibility-label.
  • After a copy, it announces "Copied" (copiedLabel), except on Android 13 and later, where TalkBack already says "Text copied".