Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Text, Heading): a truncated label shows one tooltip, not two (#5559)

freddymeta5b5f1903a8ee
diff --git a/.changeset/text-single-tooltip.md b/.changeset/text-single-tooltip.md
new file mode 100644
index 0000000000..d09fab3d61
--- /dev/null
+++ b/.changeset/text-single-tooltip.md
@@ -0,0 +1,20 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Text, Heading: a truncated label shows one tooltip, not two.
+
+When `maxLines` clipped the text, both components rendered Astryx's `Tooltip`
+**and** set the native `title` attribute to the same string. Hovering drew
+both: the styled tooltip first, then the browser's own unstyled one on top of
+it a moment later, saying exactly the same thing.
+
+The `title` goes. `Tooltip` already wires `aria-describedby` onto the anchor,
+and the full text is in the DOM either way — CSS clips it visually, so a
+screen reader was never reading the truncated version. Nothing is lost but the
+duplicate.
+
+Measured on hover, same story, before and after: `2` tooltips shown to the
+user, then `1`.
+
+@freddymeta
diff --git a/packages/core/src/Heading/Heading.tsx b/packages/core/src/Heading/Heading.tsx
index 5d6858a4c6..d503981584 100644
--- a/packages/core/src/Heading/Heading.tsx
+++ b/packages/core/src/Heading/Heading.tsx
@@ -281,7 +281,6 @@ export function Heading({
className,
{...style, ...inlineStyle},
)}
- title={tooltipEnabled ? truncation.fullText : undefined}
{...ariaProps}
{...props}>
{children}
diff --git a/packages/core/src/Text/Text.test.tsx b/packages/core/src/Text/Text.test.tsx
index 1e65c081c9..4361227f1d 100644
--- a/packages/core/src/Text/Text.test.tsx
+++ b/packages/core/src/Text/Text.test.tsx
@@ -297,3 +297,47 @@ describe('Text custom colors', () => {
expect(screen.getByText('Accent').className).toContain('accent');
});
});
+
+// A truncated Text rendered its own Tooltip AND set `title` with the same
+// string, so the browser drew a second, unstyled tooltip on top of ours.
+describe('truncated text shows one tooltip, not two', () => {
+ function withOverflow() {
+ const proto = window.HTMLElement.prototype;
+ const original = {
+ scrollWidth: Object.getOwnPropertyDescriptor(proto, 'scrollWidth'),
+ offsetWidth: Object.getOwnPropertyDescriptor(proto, 'offsetWidth'),
+ };
+ Object.defineProperty(proto, 'scrollWidth', {
+ configurable: true,
+ get: () => 400,
+ });
+ Object.defineProperty(proto, 'offsetWidth', {
+ configurable: true,
+ get: () => 100,
+ });
+ return () => {
+ if (original.scrollWidth) {
+ Object.defineProperty(proto, 'scrollWidth', original.scrollWidth);
+ }
+ if (original.offsetWidth) {
+ Object.defineProperty(proto, 'offsetWidth', original.offsetWidth);
+ }
+ };
+ }
+
+ it('leaves the native title to the tooltip it already renders', () => {
+ const restore = withOverflow();
+ try {
+ render(
+ <Text type="body" maxLines={1}>
+ A label far wider than the space it has been given
+ </Text>,
+ );
+ expect(
+ screen.getByText('A label far wider than the space it has been given'),
+ ).not.toHaveAttribute('title');
+ } finally {
+ restore();
+ }
+ });
+});
diff --git a/packages/core/src/Text/Text.tsx b/packages/core/src/Text/Text.tsx
index 9a130df9ac..9c37c897fd 100644
--- a/packages/core/src/Text/Text.tsx
+++ b/packages/core/src/Text/Text.tsx
@@ -313,7 +313,6 @@ export function Text({
className,
{...style, ...inlineStyle},
)}
- title={tooltipEnabled ? truncation.fullText : undefined}
{...props}>
{children}
</Component>