Replace Preview

Replace Preview is a copy-paste React component that stops replace-all mangles other words before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/replace-preview
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsReplace-all mangles other words

Was this component page useful?

How do I install Replace Preview?

pnpm dlx shadcn@latest add @bollard/replace-preview

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

How do I use Replace Preview in React?

replace-preview-usage.tsx
import { ReplacePreview } from "@/components/ui/replace-preview"

<ReplacePreview value={text} onValueChange={setText} defaultFind="cat" defaultReplace="dog" />

What input mistakes does Replace Preview catch?

  • Matches that sit inside longer words, with a whole-word fix
  • Total match count before applying
  • Individual matches you want to skip
  • Case of each match, preserved in the replacement (CAT → DOG)

What props does Replace Preview accept?

ReplacePreview props
PropTypeDefault
value

Controlled text being edited.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the new text after Replace or Undo.

(value: string) => void—
defaultFind

Initial search term.

string""
defaultReplace

Initial replacement.

string""
defaultWholeWord

Start with whole-word matching on.

booleanfalse
findLabel

Label of the find input.

string"Find"
replaceLabel

Label of the replace input.

string"Replace with"
partialMessage

Templates: `{count}` and `{words}` are filled in.

string"{count} inside other words ({words}), skipped."
wholeWordFixLabel

Label of the one-tap whole-word fix.

string"Whole words only"
noMatchesText

Shown when nothing matches.

string"No matches."
applyLabel

`{count}` and `{total}` are filled in.

string"Replace {count} of {total}"
doneText

`{count}` is filled in.

string"Replaced {count}."
undoLabel

Label of the Undo button after replacing.

string"Undo"

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

How is Replace Preview accessible?

  • Find and replace inputs have labels
  • Match-case, whole-word and preserve-case are aria-pressed toggles in a labelled group
  • Match list has an aria-label with the count; each include/skip control has its own label
  • Warnings and the result render in polite live regions

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

What are the limitations and server boundaries?

  • Plain-text matching, not regex
  • Word boundaries follow simple letter rules and may differ for some scripts
  • Undo covers the last replace only

What expensive mistakes does Replace Preview stop?

Replace-all mangles other words

Also known as

find and replace · replace all · search replace · bulk rename · editor · whole word · preview changes · text tool

Field type

What dependencies does Replace Preview require?

Replace Preview facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameReplace Preview
Registry identifier@bollard/replace-preview
Install commandnpx shadcn@latest add @bollard/replace-preview
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Replace Preview

What form validation mistake does Replace Preview catch?

Replace Preview prevents replace-all mangles other words. Previews every find-and-replace match in context before applying, so "cat" → "dog" doesn't turn "category" into "dogegory". Catches: Matches that sit inside longer words, with a whole-word fix, Total match count before applying, Individual matches you want to skip, Case of each match, preserved in the replacement (CAT → DOG). Limitation: validate replace-preview schemas on backend.

How do I install replace-preview with shadcn?

Run `npx shadcn@latest add @bollard/replace-preview`. Sources added: registry/default/replace-preview/replace-preview.tsx. Package requirements: lucide-react.

What props customize Replace Preview?

Replace Preview accepts `value`, `defaultValue`, `onValueChange`, `defaultFind`, `defaultReplace`. Configures find and replace, replace all, search replace behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of replace-preview?

Plain-text matching, not regex. Word boundaries follow simple letter rules and may differ for some scripts. Undo covers the last replace only Server requirement: backend verification for replace-preview.

How does Replace Preview meet accessibility guidelines?

Find and replace inputs have labels. Match-case, whole-word and preserve-case are aria-pressed toggles in a labelled group. Match list has an aria-label with the count; each include/skip control has its own label. Warnings and the result render in polite live regions. Minimizes errors: find replace whole word, replace all broke text.

Which components pair with Replace Preview?