Composants · Référence
Copy Button
An accessible clipboard copy button with success and failure announcements for screen readers.
Dernière mise à jour le 28 septembre 2026
Overview
CopyButton copies a string to the clipboard and announces copy results with an aria-live status region. It keeps the accessible name stable while the icon changes after a successful copy. Pass valueDescription for concise context, such as install command or tsx code; avoid passing the full copied value when it may be long or sensitive.
Set the active locale once with KrakstackProvider; pass locale directly only when a component needs an override. English and French defaults are built in, and messages accepts arbitrary locale keys with exact-locale, base-language, then English fallback.
Install
bunx shadcn@latest add @krak-stack/copy-buttonVariants
- Omit
copyVariantfor the default icon-only size. copyVariant="sm"renders a smaller compact icon-only button.copyVariant="large"renders the copy label next to the icon.
Usage
import { CopyButton } from "@/components/ui/copy-button";
<CopyButton
value="bun run dev"
valueDescription="install command"
copyVariant="large"
variant="secondary"
locale={locale}
messages={{ [locale]: { copy: "Copy", copied: "Copied" } }}
/>Dependencies
Registry Dependencies
Preview
Default
Small
Large