Clean Paste Input

Strips invisible characters from pasted codes and IDs, so values that look identical don't fail for hidden reasons.

StopsPasted code fails from hidden characters

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/clean-paste-input.json

The files land in your project. They're yours to edit.

Usage

clean-paste-input-usage.tsx
import { CleanPasteInput } from "@/components/ui/clean-paste-input"

<CleanPasteInput label="Coupon code" defaultValue={SAVED_DRAFT} autoComplete="off" spellCheck={false} />

What it catches

  • Zero-width spaces and joiners, and byte-order marks
  • Soft hyphens
  • Bidirectional control characters
  • Hidden characters arriving by other routes than paste, with a fix

Props

CleanPasteInput props
PropTypeDefault
label

Visible label.

string"Text"
hint

Helper text shown while there is nothing to report.

string—
multiline

Render a textarea instead of a single-line input.

booleanfalse
value

Controlled value.

string—
defaultValue

Initial value when uncontrolled.

string""
onValueChange

Called with the new value on every change.

(value: string) => void—
messages

Reword or translate any message.

Partial<typeof CLEAN_PASTE_MESSAGES>—
ref

Ref to the underlying input or textarea.

React.Ref<HTMLInputElement | HTMLTextAreaElement>—

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; the field is described by an aria-live="polite" notice
  • Undo and dismiss are buttons; dismiss has an aria-label
  • Actions return focus to the field

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Doesn't change visible look-alike characters (Cyrillic а for Latin a)
  • Removing joiners can change text in scripts or emoji that need them; use undo where that matters

What it stops

Pasted code fails from hidden characters

Also known as

zero-width · invisible characters · paste · sanitize · bom · voucher code · api key · clean input

Field type

Dependencies

Pairs well with