← All Components
<mth-copy-button>
One-click clipboard copy button with native Clipboard API, execCommand fallback, live-region announcement, and :state(copied) feedback.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-copy-button>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/copy-button"></script>
<mth-copy-button feedback-duration="2000" variant="solid">Example</mth-copy-button>import '@methane-ui/ui/copy-button';
import '@methane-ui/react';
export function Example() {
return <mth-copy-button feedback-duration="2000" variant="solid">Example</mth-copy-button>;
}<script setup lang="ts">
import '@methane-ui/ui/copy-button';
</script>
<template>
<mth-copy-button feedback-duration="2000" variant="solid">Example</mth-copy-button>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/copy-button';
import { MthCopyButtonDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthCopyButtonDirective],
template: `<mth-copy-button feedback-duration="2000" variant="solid">Example</mth-copy-button>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/copy-button';
import MthCopyButton from '@methane-ui/svelte/MthCopyButton.svelte';
</script>
<MthCopyButton feedback-duration="2000" variant="solid">Example</MthCopyButton>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
value | value | string | "" | Text value to copy directly to the clipboard. |
target | target | string | "" | Optional element ID or CSS selector from which to read text/value when value is omitted. |
feedbackDuration | feedback-duration | number | 2000 | Duration in milliseconds to display copied feedback. |
variant | variant | 'solid' | 'outline' | 'ghost' | "outline" | Button variant (solid, outline, or ghost). |
size | size | 'sm' | 'md' | 'lg' | "md" | Button size (sm, md, or lg). |
disabled | disabled | boolean | false | Disables interaction. |
label | label | string | "" | Accessible aria-label in idle state. |
copiedLabel | copied-label | string | "" | Accessible label/announcement text when copied. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-copy | { value: string; method: string } | Fired when text is successfully copied to the clipboard. |
mth-copy-error | { reason: string } | Fired if copying fails or no copyable text is available. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| Enter | both | Button is focused and enabled | Copies value to clipboard and announces copied feedback |
both | Button is focused and enabled | Copies value to clipboard and announces copied feedback |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 2 APG keyboard transitions across LTR/RTL. | mth-copy-button.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(copied), :state(disabled). | Conformance suite |
| i18n | Routes 2 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |