Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ellipsis truncation in Token #2974

Merged
merged 3 commits into from
Mar 7, 2023
Merged

Fix ellipsis truncation in Token #2974

merged 3 commits into from
Mar 7, 2023

Conversation

iansan5653
Copy link
Contributor

@iansan5653 iansan5653 commented Mar 2, 2023

Text in Token is supposed to truncate with an ellipsis when the Token reaches 100% of the container width. But the TokenTextContainer has overflow: visible, which disables truncation. Removing that rule allows the preceding overflow: hidden line to activate.

However, in inline elements overflow cannot be hidden only in the x direction, so overflow: hidden will also clip descenders (like the tail on a "g"). To fix this, we also need to also change the line-height to normal.

Before:
screenshot of token showing text spilling past the end

After:
screenshot of token showing text truncated with ellipsis (three dots)

@iansan5653 iansan5653 requested review from a team and langermank March 2, 2023 20:49
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2023

🦋 Changeset detected

Latest commit: b9f3a69

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 94.65 KB (-0.01% 🔽)
dist/browser.umd.js 95.22 KB (-0.01% 🔽)

@iansan5653 iansan5653 temporarily deployed to github-pages March 2, 2023 20:56 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2974 March 2, 2023 20:56 Inactive
@iansan5653 iansan5653 temporarily deployed to github-pages March 3, 2023 21:05 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2974 March 3, 2023 21:06 Inactive
@joshblack
Copy link
Member

@iansan5653 this might be out of scope for this PR, but from an a11y perspective would we need to provide a mechanism for someone to view the full label contents if it is truncated? Otherwise could this fall under: https://www.w3.org/TR/WCAG21/#resize-text

@iansan5653
Copy link
Contributor Author

I totally agree. That being said I'm not sure what a good answer is in this case:

  • We could encourage shorter text, but sometimes the text is user-controlled (ie in issue labels)
  • We could allow the token to break apart across lines, but I have a feeling designers really won't like the look of that
  • We could allow the text inside the token to wrap, but that would cause Token to have a dynamic height. One of the primary purposes of Token is to work with other tokens in the same group, so uniformity in height is really important
  • We could show the text in a Tooltip on hover/focus. But what about when the Token is a non-focusable span? Should it always be focusable? Do we have a mechanism for showing a tooltip without duplicating the content for screen readers (ie, an aria-hidden tooltip)? Our Tooltip component is generally not accessible anyway, so that starts raising even more problems. Tokens on project board cards also already have tooltips, so there is also a conflict there. And how do we know when to show the tooltip? If we do it when there is no overflow, it will look buggy, but there is no API to detect text overflow. All kinds of concerns here unfortunately
  • We could show the full text in a dialog on click. This also raises focus issues, and since Token is already clickable in some cases (renderable as a button with onClick), this will conflict
  • We could make the text horizontally scrollable. This is another accessibility violation but maybe one that isn't as bad? But there is no CSS for a scrollable ellipsis overflow. And we risk showing horizontal scrollbar inside the token, which again breaks that height consistency
  • We could put the full text in a title attribute, but this only fixes the problem for mouse users since title only renders on hover

I don't think this fix makes the accessibility problem worse - the current situation with visual overflow is a bug that does need to be fixed. Generally I think the first option (encourage shorter text) is preferred. When user-controlled though, we do have to do something.

@joshblack
Copy link
Member

@iansan5653 thanks for taking the time to write this up! I appreciate it so much 🙏 And definitely agreed with what you shared around.

I'm not sure how much we could build-in to this component due to the different circumstances you shared, but what would you think of this as a rule of thumb:

  1. If you can avoid truncation, please do that instead
  2. If you need to truncate, use a tooltip
  3. If the content that is being truncated is interactive, place the tooltip on the interactive element
  4. If the content that is being truncated is non-interactive, use a toggletip

@iansan5653
Copy link
Contributor Author

Yep, that sounds about right to me 👍. That seems like something we could use an interface guideline document for.

In the meantime, are you OK with merging this PR?

@joshblack
Copy link
Member

@iansan5653 definitely 👍 it seems like this is similar to some other components so I'll make a note of this under the umbrella of truncation so we can revisit it!

@iansan5653 iansan5653 added this pull request to the merge queue Mar 7, 2023
Merged via the queue into main with commit 6a795da Mar 7, 2023
@iansan5653 iansan5653 deleted the fix-token-overflow branch March 7, 2023 16:24
@primer-css primer-css mentioned this pull request Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants