Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-copy-button>

@methane-ui/ui~6.8 KB brotli (cold + Lit)~1.4 KB marginal

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

Interactive StageLive Custom Element · <mth-copy-button> (@methane-ui/ui)
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>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
valuevaluestring""Text value to copy directly to the clipboard.
targettargetstring""Optional element ID or CSS selector from which to read text/value when value is omitted.
feedbackDurationfeedback-durationnumber2000Duration in milliseconds to display copied feedback.
variantvariant'solid' | 'outline' | 'ghost'"outline"Button variant (solid, outline, or ghost).
sizesize'sm' | 'md' | 'lg'"md"Button size (sm, md, or lg).
disableddisabledbooleanfalseDisables interaction.
labellabelstring""Accessible aria-label in idle state.
copiedLabelcopied-labelstring""Accessible label/announcement text when copied.

Events

EventDetail TypeDescription
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

KeyDirectionWhenExpected Behavior
EnterbothButton is focused and enabledCopies value to clipboard and announces copied feedback
bothButton is focused and enabledCopies value to clipboard and announces copied feedback

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 2 APG keyboard transitions across LTR/RTL.mth-copy-button.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(copied), :state(disabled).Conformance suite
i18nRoutes 2 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test