Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Input Group examples · Buttons

Copy Button Input Group for React

A read-only link with a copy button that turns into a check once copied.

Framework
UI library

Let people copy a link, key or code without selecting it. The InputGroupInput is read-only and holds the link; the button at its end writes it to the clipboard and shows a check for two seconds, then goes back to the copy icon.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

What does the copy button change when it is clicked?

It writes the link to the clipboard with navigator.clipboard.writeText, then sets a copied flag that swaps the copy icon for a check. A timeout clears the flag after 2000 ms.

What name does the button have?

Copy, and Copied while the check shows: aria-label follows the same flag as the icon, so screen readers hear the change too.

Can the value in the field be edited?

No. readOnly keeps the value fixed but still lets people focus and select it. The addon comes after the input with align="inline-end", so the button sits at the end.

Does clicking the button also focus the field?

No. The addon ignores clicks that land on a button, so only the copy runs. A click on the addon's empty space would focus the input.

How long does the check icon stay?

2000 ms. Change the timeout in the handler for a longer or shorter confirmation.

Why doesn't copying work on my page?

The Clipboard API needs a secure context (HTTPS or localhost) and a user action such as this click. On plain HTTP navigator.clipboard is undefined.