Intelligently truncate long strings with interactive expansion and full searchability
Most apps display addresses truncated to their first and last few
characters (e.g. 0xd8dA...6045).
Address poisoning scams
exploit this: attackers generate addresses matching the visible prefix
and suffix, seed them into transaction histories, and wait for users to
copy the wrong one.
Truncation hides the characters that matter most for
verification.
This component keeps the full value in the DOM at all times. The middle portion is visually collapsed with CSS, but never removed:
npm install @umplabs/truncated-value
# or
pnpm add @umplabs/truncated-value
Or use the CDN with no bundler required:
<script src="https://unpkg.com/@umplabs/truncated-value/dist/truncated-value.iife.global.js"></script>
<script src="https://unpkg.com/@umplabs/truncated-value/dist/truncated-value.iife.global.js"></script>
<truncated-value value="0x1234567890abcdef1234567890abcdef12345678" expandable></truncated-value>
import { TruncatedValue } from '@umplabs/truncated-value/react';
<TruncatedValue
value="0x1234567890abcdef1234567890abcdef12345678"
startLength={6}
endLength={4}
expandable
/>
import '@umplabs/truncated-value/web-component';
<truncated-value value="0x1234567890abcdef1234567890abcdef12345678" expandable />
This component ships with no visual opinions — no colors, fonts, sizes, or spacing. The only built-in CSS handles the truncation mechanics. Everything else is up to you, so it fits naturally into any design system or brand.
Use the ::part() selector to style shadow DOM parts:
truncated-value::part(container) {
font-weight: bold;
}
truncated-value::part(start),
truncated-value::part(end) {
color: #888;
}
Use the className / style props and target CSS
classes:
.truncated-value { font-weight: bold; }
.tv-middle { /* hidden middle text */ }
.tv-ellipsis { /* the ellipsis indicator */ }