Skip to content

feat: Add TruncatedText component#4543

Open
avinashbot wants to merge 3 commits into
mainfrom
feat/truncated-text-component
Open

feat: Add TruncatedText component#4543
avinashbot wants to merge 3 commits into
mainfrom
feat/truncated-text-component

Conversation

@avinashbot
Copy link
Copy Markdown
Member

@avinashbot avinashbot commented May 20, 2026

Description

Releases a new component, TruncatedText, based on tooltip, which handles things like truncation detection, correct
ARIA roles, and pointer and keyboard behavior.

Related links, issue #, if available: n/a

How has this been tested?

Unit tests, and a new visual test page for screenshot testing (will add pipeline test after merge)

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.43%. Comparing base (9b5fbfb) to head (b3a823a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4543   +/-   ##
=======================================
  Coverage   97.42%   97.43%           
=======================================
  Files         938      941    +3     
  Lines       29680    29720   +40     
  Branches    10787    10798   +11     
=======================================
+ Hits        28917    28957   +40     
  Misses        756      756           
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avinashbot avinashbot marked this pull request as ready for review May 21, 2026 08:09
@avinashbot avinashbot requested a review from a team as a code owner May 21, 2026 08:09
@avinashbot avinashbot requested review from a team, georgylobko and jperals and removed request for a team and georgylobko May 21, 2026 08:09
export default function TruncatedTextSimple() {
return (
<ScreenshotArea>
<h1>TruncatedText examples</h1>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the page header should preferably be ourside the screenshot area

<Box>
<Box variant="awsui-key-label">With CopyToClipboard, internal truncation</Box>
<div style={containerStyle}>
<CopyToClipboard
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this wrapping after the icon expected because builders should instead wrap the CopyToClipboard inside TruncatedText, as in the previous element?

Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not entirely expected; there's a parallel update to the component to support single-line wrapping; which has released since this PR was created. Will rebase.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reproducible after updating the branch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine in the permutations page - just didn't update this one to add wrapText.

Comment thread pages/truncated-text/simple.page.tsx
Comment thread src/truncated-text/index.tsx Outdated
if (element) {
// useResizeObserver fires initially at layoutEffect-time where the initial calculation
// is performed, but the calculation isn't always correct at that stage.
setTimeout(() => setIsTruncated(element.scrollWidth > element.clientWidth), 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any alternative where arbitrary timeouts are not needed, such as requestAnimationFrame? We use requestAnimationFrame in 36 other places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use rAF, but it was still flaky. It's hard to tell at what point during rendering that wrapping/truncation happens, but it looks like every browser is a little unique in that regard, and this seemed to work the most consistently (timeout of 0 didn't work either).

return (
<ScreenshotArea>
<h1>TruncatedText examples</h1>
<SpaceBetween size="m">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: permutations make the screenshots more isolated, and handle future additions more gracefully

Comment thread src/truncated-text/styles.scss Outdated
Comment thread src/truncated-text/styles.scss
expect(element).toHaveTextContent('Some text');
});

test('applies the test-utils root class', () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking but I'd say this test is superfluous —what matters is that the test utils work. Which is kind of covered since renderTruncatedText relies on findTruncatedText, although not very explicitly.

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.

2 participants