Width-aware truncation - #3325
Open
benjaminleonard wants to merge 3 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This has long been on my list to fix. The char-based truncation we have currently leaves a lot of unused space and is unreliable. In part because character widths (plus kerning) vary so much between two strings of identical number of characters.
<Truncate>now fills its container and truncates based on actual rendered width.position="end"is pure CSS (text-overflow: ellipsis). JS only checksscrollWidth > clientWidthon hover to decide whether to show the full-text tooltipposition="middle"measures with canvasmeasureText(accounts for kerning and letter-spacing) and searches for the longest string that fitsAlso standardizes ID display: IDs now middle-truncate everywhere, and adds truncation + copy buttons to places that had none. FileInput gets
contain: inline-sizeon its label, fixing a bug where it forces the input wider. I think this predates the truncation change.Test changes to match.
From some local robot tests, the truncation measurements, including the binary-search are all very quick.
This also means we aren't truncating when there is space to display, before: