A “label: value” row for details pages and admin panels. The value sits in a field with a CopyButton (variant="inline") at its end: the icon turns into a check mark after copying. CopyField only adds the label, truncation and masking, copying itself is done by CopyButton and useCopyToClipboard.
Browser Support
Feature
Baseline
Your browser
Async clipboard
Copies the field value.
Your browser:
Preview
Click the icon at the end of a field, or move to it with Tab and press Enter.
Customer
Name
Alex Morgan
Email
alex.morgan@example.com
Phone
+1 555 0142 778
Order
ORD-2048-7731
Installation
Usage
import { CopyField } from "@/components/ui/copy-field"
export function CustomerCard() {
return (
<div className="space-y-1">
<CopyField label="Email" value="alex.morgan@example.com" labelClassName="w-20" />
<CopyField label="Order" value="ORD-2048-7731" mono labelClassName="w-20" />
</div>
)
}Examples
Long values
By default a long value is cut to one line and the full text goes to the tooltip. With truncate={false} it wraps instead.
Address
221 Pine Street, Apartment 14, Springfield, 49201
Address
221 Pine Street, Apartment 14, Springfield, 49201
<CopyField label="Address" value={address} />
<CopyField label="Address" value={address} truncate={false} />Masked value
displayValue changes what is shown, while the full value is still what gets copied.
API key
demo_key••••••••6wcy
<CopyField
label="API key"
value={apiKey}
displayValue={`${apiKey.slice(0, 8)}••••••••${apiKey.slice(-4)}`}
mono
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | - | Text before the value |
| value | string | - | Value to show and copy |
| displayValue | ReactNode | - | What to show instead of value. Copying still uses value |
| mono | boolean | false | Monospace font for IDs, keys and codes |
| truncate | boolean | true | Cut to one line with the full value in title |
| timeout | number | 2000 | How long the confirmation stays, in ms |
| labels | { copy?: string; copied?: string } | { copy: "Copy", copied: "Copied" } | Accessible names of the copy button before and after copying |
| labelClassName | string | - | Classes for the label, e.g. a fixed width to align rows |
| valueClassName | string | - | Classes for the value |
| onCopy | (value: string) => void | - | Called after a successful copy |
| onCopyError | (error: Error) => void | - | Called when the browser refuses to copy |
| className | string | - | Additional CSS classes |