Magoo Component UI logo Magoo Component UI
← Catalog

Copy to Clipboard

copy-to-clipboard atom experimental

A button that copies a value to the clipboard and briefly confirms with a "Copied!" state.

The width preview needs a screen wider than the chosen width — use a larger device (or a desktop browser) to see the desktop and tablet layouts.

Default
Icon

Props

NameTypeReq
value string ✓
label string
copied_label string
variant enum (button | icon)

Related components

How to use

behavior.js copies data-value via navigator.clipboard.writeText, then toggles data-copied on the button between "true" and "false" (reverting after ~1.5s). The label/icon swap is pure CSS driven by that attribute (group-data-[copied=true]:* variants) rather than a bare hidden class toggled in JS, and the copied/default states cross-fade in place using a grid stack so there is no layout shift. A bubbling "copy" CustomEvent carries { value } in its detail. The click listener and the reset timer are cleaned up on teardown. Clipboard writes can fail in insecure contexts; the visual feedback still shows.

Use cases

actioninline WCAG AA SEO 20 dir: both ai-generated