Middle Truncate

Truncates long names and IDs in the middle at the real rendered width, so the end that tells files or wallets apart stays visible.

StopsPicked the wrong file by prefix

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/middle-truncate.json

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

Usage

middle-truncate-usage.tsx
import { MiddleTruncate } from "@/components/ui/middle-truncate"

<MiddleTruncate value={item.value} className={item.mono ? "flex-1 font-mono text-[13px]" : "flex-1"} />

What it catches

  • Lookalike items that differ only at the end
  • File extensions cut off
  • Emoji or accented characters split in half

Props

MiddleTruncate props
PropTypeDefault
value* (required)

The full text. It stays available to copy, `title` and screen readers.

string—
minTail

Characters always kept at the end. Defaults to the file extension, or 4.

number—
ellipsis

Marker inserted where text is removed.

string"…"

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

Accessibility

  • The full value is in the accessibility tree; the truncated display is aria-hidden
  • Full value is also in the title when truncated
  • Copy puts the full value on the clipboard, not the ellipsis

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

Limitations

  • Measures width in the browser after layout, so server-rendered HTML shows the full value until hydration
  • Very narrow containers may still show only a few characters

What it stops

Picked the wrong file by prefix

Also known as

truncate · ellipsis · wallet address · file name · transaction id · hash · text overflow · web3

Field type

Dependencies

None beyond React and Tailwind CSS.

Pairs well with