Skip to content

PasteField

The paste-side companion to CopyField. Drop it wherever you need a labelled, accessible paste target — a Zone that accepts keyboard paste and drop, a Trigger button that calls the Clipboard API, and a Status indicator that reflects the current state.

Paste or drop text, a screenshot or an image file. Images are verified from their bytes.
Drop an image here, or click and press Ctrl + V or ⌘ + V
Ready

Zone, trigger, status and preview

PasteField.Zone takes Ctrl/⌘+V and drops through the same checks; only drags it accepts get the drop cursor, and data-drag-over marks them. PasteField.Preview shows text, image thumbnails and file names, never pasted HTML. Image URLs are released when the result changes. Clear calls reset(), which also cancels a read in flight.

<PasteField.Root label="Attachments" pasteOptions={{ accept: ['text', 'image'] }}>
  <PasteField.Zone />
  <PasteField.Trigger />
  <PasteField.Status />
  <PasteField.Preview placeholder="Nothing pasted yet" />
</PasteField.Root>
import { PasteField } from "react-smart-copy";
export function NotesPasteField() {
return (
<PasteField.Root
label="Notes"
pasteOptions={{ accept: ["text", "image"], onPaste: (result) => setNotes(result.text ?? "") }}
>
<PasteField.Label />
<PasteField.Status /> {/* "Ready" → "Reading…" → "Pasted" → "Error" */}
<PasteField.Zone /> {/* focusable paste target; accepts Ctrl/⌘+V and drops */}
<PasteField.Trigger /> {/* "Paste" → "Pasting…" → "Pasted" → "Retry" */}
<PasteField.Preview placeholder="Nothing pasted yet" /> {/* text, thumbnails, file names */}
</PasteField.Root>
);
}
Part Renders Notes
PasteField.Root div Props: label, pasteOptions, messages, alwaysVisible, announce, pendingDelayMs, minPendingMs. Forwards ref and all div props
PasteField.Label span Defaults to label
PasteField.Status span Text label per status. Defaults: idle → "Ready", reading → "Reading…", read → "Pasted", error → "Error". Custom labels prop
PasteField.Zone div role="region" Focusable paste target (tabIndex=0); handles Ctrl/⌘+V itself. Named “Paste area for {label}” via aria-label (override with aria-label, aria-labelledby or messages.zoneLabel). Sets aria-keyshortcuts="Control+V Meta+V". focusable={false} removes tabIndex. Accepts drag-and-drop and sets data-drag-over while an accepted drag is over it; droppable={false} turns drops off. Announces messages.dropped, or your own pasted message if you only translated that one. Your own onDrag* / onDrop handlers run first, and calling preventDefault() in one takes over
PasteField.Trigger button type="button" Children can be a node or ({ status, displayStatus, state, revealed, canRetry }) => node. aria-busy while reading; never disabled, so focus stays put
PasteField.Preview div What was pasted: text (truncated at maxTextLength, default 2000), image thumbnails (imageAlt for alt text) and non-image file names. Never renders pasted HTML. Shows placeholder until there is a result. Object URLs are revoked on change and unmount. Pass ({ result, imageUrls }) => node to render it yourself
usePasteField() — Full context, for building your own parts inside PasteField.Root

Styling hooks on Root, Zone and Trigger: data-display-state="idle | reading | read | error" (style with this one), data-state (the raw state), and data-revealed while the trigger should be visible. The Zone also has data-drag-over:

[data-zone][data-drag-over] { outline: 2px dashed currentColor; }
<PasteField.Root
label="Resume"
messages={{
pasted: (result) => `Got ${result.text?.length ?? 0} characters`,
dropped: (result) => `Added ${result.files.length} dropped files`,
error: (e, source) => t(`${source === "drop" ? "drop" : "paste"}.errors.${e.type}`),
triggerLabel: (label) => `Paste ${label}`,
zoneLabel: (label) => `Drop zone for ${label}`,
}}
/>