Text Diff

Text Diff is a copy-paste React component that stops approved an edit i didn't see 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/text-diff
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

StopsApproved an edit I didn't see

Was this component page useful?

How do I install Text Diff?

pnpm dlx shadcn@latest add @bollard/text-diff

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

How do I use Text Diff in React?

text-diff-usage.tsx
import { TextDiff } from "@/components/ui/text-diff"

<TextDiff before={before} after={after} view={view} />

What input mistakes does Text Diff catch?

  • Changed numbers, kept whole (1,250.50 is one token) and called out
  • Whitespace, line-break and zero-width character changes, drawn visibly
  • Identical texts, said plainly
  • Counts of words added and removed

What props does Text Diff accept?

TextDiff props
PropTypeDefault
before* (required)

The original text.

string—
after* (required)

The changed text.

string—
view

`inline` interleaves changes; `split` shows before and after side by side.

"inline" | "split""inline"
showStats

Show the word counts and the "numbers changed" / "invisible change" callouts.

booleantrue
beforeLabel

Heading of the left column in split view.

string"Before"
afterLabel

Heading of the right column in split view.

string"After"
addedText

Templates: `{count}` is filled in.

string"+{count} added"
removedText

Count label for removed words.

string"−{count} removed"
numbersText

Lead-in before the changed numbers ("30 → 14, 4417 → 4471").

(count: number) => string(count) => (count === 1 ? "Number changed:" : `${count} n…
invisibleText

Count label for invisible-character changes.

(count: number) => string(count) => (count === 1 ? "1 invisible change" : `${count…
identicalText

Shown instead of the stats when the two texts are the same.

string"No changes"
srAddedLabel

Read before each change by screen readers.

string"added: "
srRemovedLabel

Screen-reader prefix for removed text.

string"removed: "

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

How is Text Diff accessible?

  • Added and removed runs carry sr-only labels (srAddedLabel/srRemovedLabel)
  • Invisible characters have a title tooltip
  • Icons are aria-hidden

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

What are the limitations and server boundaries?

  • Word-level, not semantic: reworded sentences show as remove + add
  • Very large diffs fall back to a coarser result past the memory budget

What expensive mistakes does Text Diff stop?

Approved an edit I didn't see

Also known as

diff · text compare · track changes · review · contract · redline · word diff · diffchecker

Field type

What dependencies does Text Diff require?

Text Diff facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameText Diff
Registry identifier@bollard/text-diff
Install commandnpx shadcn@latest add @bollard/text-diff
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 Text Diff

What form validation mistake does Text Diff catch?

Text Diff prevents approved an edit I didn't see. Shows a word-level diff that makes changed numbers and invisible whitespace changes visible, so an edit can't slip through unseen. Catches: Changed numbers, kept whole (1,250.50 is one token) and called out, Whitespace, line-break and zero-width character changes, drawn visibly, Identical texts, said plainly, Counts of words added and removed. Limitation: validate text-diff schemas on backend.

How do I install text-diff with shadcn?

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

What props customize Text Diff?

Text Diff accepts `before`, `after`, `view`, `showStats`, `beforeLabel`. Configures diff, text compare, track changes behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of text-diff?

Word-level, not semantic: reworded sentences show as remove + add. Very large diffs fall back to a coarser result past the memory budget Server requirement: backend verification for text-diff.

How does Text Diff meet accessibility guidelines?

Added and removed runs carry sr-only labels (srAddedLabel/srRemovedLabel). Invisible characters have a title tooltip. Icons are aria-hidden. Minimizes errors: hidden change in text, zero width characters.

Which components pair with Text Diff?