Skip to content

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

Merged
freddymeta merged 3 commits into
mainfrom
fix/text-double-tooltip
Aug 27, 2026
Merged

freddymeta merged 3 commits into
mainfrom
fix/text-double-tooltip

Conversation

@freddymeta

Copy link
Copy Markdown
Contributor

Summary

A truncated Text renders Astryx's Tooltip and sets the native title attribute to the same string — both gated on the same tooltipEnabled. Hovering draws both: the styled tooltip first, then the browser's own unstyled one on top of it a moment later, saying exactly the same thing.

It is visible on the docsite today:

-        title={tooltipEnabled ? truncation.fullText : undefined}

Same line in Heading.tsx.

Measured in Chromium

Same story, native title presence plus a count of visible [role="tooltip"] elements after hover:

native title visible Astryx tooltip shown to the user
main yes 1 2
this PR no 1 1

Why the title goes and not the Tooltip

  • Tooltip already carries the a11y contract. It sets aria-describedby on its anchor (Tooltip.tsx:253-256), verified still present after this change.
  • The full text was never hidden from assistive tech. CSS clips it visually; the DOM still holds all 191 characters, measured. title was not what made the truncated text readable to a screen reader.
  • title is the weaker affordance anyway — unstyleable, unplaceable, no touch support, and its own delay is what makes the doubling look like a glitch rather than a design.

So the duplicate is all that is lost.

Test plan

  • New test: a truncated Text carries no title. Negative control: putting the attribute back fails exactly that test.
  • pnpm build, check:repo, lint:strict, core + storybook typechecks — clean. Text + Heading + Tooltip suites green.
  • No existing test asserted the title (checked before removing it).

Note

Badge gains the same tooltip in a follow-up; it will use the Tooltip alone rather than reintroducing this pair.

@freddymeta

When `maxLines` clipped the text, both components rendered Astryx's `Tooltip`
AND set the native `title` attribute to the same string, both gated on the
same `tooltipEnabled`. Hovering drew both — the styled tooltip, then the
browser's own unstyled one on top of it a moment later, saying exactly the
same thing.

The `title` goes rather than the `Tooltip`: `Tooltip` already sets
`aria-describedby` on its anchor, and the full text is in the DOM either way
since CSS clips it visually, so a screen reader was never reading the
truncated version. The duplicate is all that is lost.

Measured in Chromium on the same story — native title present, and visible
`[role="tooltip"]` elements counted on hover:

  main:    title set + 1 tooltip  => 2 shown to the user
  this PR: no title  + 1 tooltip  => 1

Test asserts a truncated Text carries no `title`; it fails when the attribute
is put back.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 26, 2026
@vercel

vercel Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 26, 2026 10:17am

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 26, 2026
A worktree-local symlink to a sibling install got committed with the change,
and `pnpm install --frozen-lockfile` then fails on it — which is why every
job on this PR went red before reaching any build step. Nothing to do with
the change itself.
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Heading (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 151 -
Complexity N/A High (22) -
Text (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 520 -
Complexity N/A High (24) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: 2 accessibility violation(s) found — 2 serious.

Heading - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/16 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Text - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/23 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

Status: Skipped — 546 shots exceeds the 240-shot budget (2 components touched) — too broad to review shot by shot here. The daily release gate covers this change against the full baseline.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 26, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, good catch — dropping title rather than the Tooltip is the right way round. Chromium confirms truncated Text and Heading now expose one tooltip.

[Reviewed by Robohands]

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 26, 2026
@freddymeta
freddymeta merged commit 5b5f190 into main Aug 27, 2026
23 checks passed
@github-actions
github-actions Bot deleted the fix/text-double-tooltip branch August 27, 2026 09:11
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Aug 28, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Sep 12, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Sep 21, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Sep 24, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Oct 30, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Oct 31, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Nov 4, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
HelloOjasMutreja added a commit to HelloOjasMutreja/astryx that referenced this pull request Nov 5, 2026
…merged ref

Carries over the two patterns Text/Heading landed in meta#5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.
cixzhang added a commit that referenced this pull request Nov 8, 2026
* feat(lab): add LineClamp — clamp arbitrary content to N lines

Text's maxLines truncates a single text node; LineClamp is the composable
version, wrapping arbitrary children (mixed inline content, nested elements)
and clamping the whole block to N lines. Reuses useTruncation (the same
overflow-detection hook Text uses) rather than reinventing measurement, and
the same optional-tooltip-on-truncation pattern.

Lands in @astryxdesign/lab per the lab -> core graduation path. No changeset:
lab is private and not published to npm.

Closes #4180

* fix(lab): correct docs-types import path in LineClamp.doc.mjs

Lab components import docs-types from packages/core/src, not a local
../docs-types (that path only resolves inside packages/core/src/*).

* fix(lab): correct docs-types import path in LineClamp.doc.mjs

LineClamp.doc.mjs still imported types from the removed
packages/core/src/docs-types module (pre-dating the doc-types
migration to @astryxdesign/cli/authoring) -- broke build-storybook's
typecheck:docs step. Also renamed the bare TranslationDoc type to
ComponentTranslationDoc, matching its actual exported name under the
new module and sibling doc.mjs files' convention.

* fix(lab/LineClamp): drop native title/tooltip pairing, stabilize the merged ref

Carries over the two patterns Text/Heading landed in #5559:
- Stop pairing a native title with the Tooltip on the same element. The
  browser's own title tooltip and our Tooltip both fire on hover, so a
  truncated LineClamp announced its full content twice.
- Replace the inline mergeRefs(...) call (a fresh callback ref every
  render) with useMergedRefs, matching Text's stable ref.

* fix(lab): keep clipped focusable descendants out of LineClamp's tab order

Two related keyboard-focus bugs in clamped content with focusable
descendants (e.g. a trailing link past maxLines):

- overflow: hidden makes the clamp box a scroll container, so focusing
  a clipped descendant scrolls the box to bring it into view -
  replacing the visible line with the hidden one out from under the
  reader. Switched to overflow: clip, which clips the same way but
  isn't a scroll container, so that scroll-into-view path never fires.

- A descendant on a visually clipped line is still in the DOM and
  still tabbable regardless of which overflow value is used -
  line-clamp only clips paint, not layout. A new effect compares each
  focusable descendant's rect against the clamp box's own (clipped)
  rect and removes anything past the fold from the tab order
  (tabindex="-1", aria-hidden="true"), restoring each descendant's own
  original state once it's no longer clipped. Runs on every render
  (children/maxLines changes) and via the same shared ResizeObserver
  useTruncation already uses (a resize can un-clip a descendant
  without the overall isTruncated flag ever changing).

Verified against a real Storybook story reproducing the exact
scenario: a trailing link past maxLines is confirmed geometrically
clipped, confirmed excluded from the real tab order
(element.tabIndex, not just the attribute), and confirmed restored
after a render with different geometry. The pure-resize-without-
render path (no accompanying prop change) could not be independently
verified in this environment - this remote browser tool's viewport
resize doesn't dispatch native resize events or ResizeObserver
notifications at all here, confirmed via a minimal same-realm
ResizeObserver test unrelated to this component's own code. It reuses
the exact observeResize/unobserveResize utility useTruncation already
relies on for the same purpose, so it isn't new, unproven machinery.

Added regression tests using a mocked getBoundingClientRect (jsdom has
no layout engine, so real clamping never actually clips in tests) for
all three states: hide-when-clipped, leave-alone-when-visible, and
restore-original-state-when-no-longer-clipped (including preserving a
consumer's own explicit tabIndex through the hide/restore cycle).

Fixes #4259.

* fix(lab): import afterEach in LineClamp's focus-restore tests

Missed importing afterEach when adding the keyboard-focus regression
tests; vitest's implicit globals let it pass at runtime, but strict
typecheck (tsc --project tsconfig.json) caught the missing import.

* chore(registry): refresh ShadCN route lock for lab LineClamp

* fix(lab): LineClamp one-line tooltip, late focusables, and docs accuracy

* fix(lab): LineClamp keyboard reveal, focus-safe hiding, official-packages entry

* chore(changeset): name the CLI for the official-packages entry

* fix(lab): LineClamp hides clipped descendants with inert, re-syncs on focusout, shares one observer

* fix(lab): LineClamp keeps a caller's inert; mark the tooltip best practice as guidance

* fix(lab): LineClamp uses Core's focusable selector and shared mutation observer, subscribes through a callback ref, and names its switch hasTruncateTooltip

A clipped summary, contenteditable, iframe or media control is now hidden from the tab order, as Core's canonical selector lists them. The inert hand-off counts the clamp's own writes, so a link restored and hidden again in one task keeps its marker. The observers attach and release with the root through a callback ref, the focusout sync is the root's onBlur composed with the caller's, and hasTooltip is renamed to hasTruncateTooltip to match Text and Heading. observeMutations hands each registration its records, and an internal line-clamp entry exposes the selector and the observer to Lab.

* fix(lab): LineClamp leaves a nested clamp's links to the nested clamp and keeps its observers attached through renders

A clamp now manages only the descendants whose nearest clamp root is itself, so an outer clamp no longer restores or disowns a link an inner clamp hid. The observers attach to the root held in state instead of a callback ref, so a caller's inline callback ref no longer detaches them and resets the count of the clamp's own inert writes on every render.

* fix(lab): LineClamp attaches its observers through a callback ref again and tells its own inert writes from a caller's by what they do

The observers attach in a callback ref, as the component runtime rules require. The clamp no longer counts its own inert writes, which a re-attach or a clamp mounting inside another could lose track of: a caller's write is recognised from the attribute's old and new values instead, so it does not depend on when the observer attached.

* Merge main into feat/lab-line-clamp

sharedMutationObserver: main's deliver and flushMutations, with this
branch's per-registration records and attributeOldValue key.
package.json and sync-exports: both internal entries (main's
dialog-context and scroll-anchoring, this branch's line-clamp), in the
order sync-exports writes.

* fix(lab): LineClamp splits its tooltip switch from its placement and keeps a caller's queued inert

hasTruncateTooltip is an on/off switch, as Text's is, and the new
truncateTooltipPlacement sets where the tooltip opens (default 'above').
The tooltip props follow Text's when Text's switch is renamed.

A caller's inert write could be lost before the clamp saw it: when the
observers re-subscribe with no other clamp mounted (an inline callback
ref, or a maxLines change), and when the caller sets inert in the render
that un-clips the link. The clamp now hands back queued records before
each sync and before it unsubscribes.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp's release hands back a caller's inert without measuring

The release runs in React's commit, before the clamp writes its new line
count, so syncing there laid the page out a second time. It now only
hands back the queued records; the layout effect syncs once the commit
is done.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): a release defers every clamp's clipping pass until the commit is done

The release flush delivered other clamps' queued records too, and their
clipping passes measured inside React's commit. During a release flush,
every clamp now hands back its caller's inert at once and defers its
pass to a microtask after the commit; the releasing clamp skips its own.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp mounts its tooltip on first interest through Core's shared truncation tooltip

LineClamp mounted a lazily loaded Tooltip for every truncated clamp at
load. It now uses Core's TruncationTooltip and its interest hook, as Text
and Heading do: the tooltip mounts on the first hover, completed tap or
focus, so a page of clamped content mounts no tooltip layers at load.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp's tooltip content uses the shared truncation tooltip style

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): a truncated LineClamp shows the shared keyboard focus outline

A truncated clamp is a tab stop, but its root drew the browser's default
ring flush on the text. It now uses the shared focus-visible outline and
the theme's focus tokens.

Co-authored-by: HelloOjasMutreja <[email protected]>

* test(lab): a truncated LineClamp sets no native title, and a stable ref is called once

Co-authored-by: HelloOjasMutreja <[email protected]>

* chore(changeset): the Core internal entry and the shared mutation observer's records are a Core patch

Co-authored-by: HelloOjasMutreja <[email protected]>

* Merge branch 'main' into feat/lab-line-clamp

* fix(lab): LineClamp checks its clipped links again when a web font loads

A web font that loads after the first pass can re-wrap the lines at the
same box size, so no resize or render runs. A link pushed onto a hidden
line kept its tab stop, and a link pulled onto a visible line stayed
inert. The clipping pass now also runs on each document font load.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp checks its clipped links on every crossing of the clip edge

Lines can re-wrap at the same box size with no render, mutation, resize
or font event: a FontFace added after it loads, or an ancestor that
changes to an installed font. An IntersectionObserver rooted at the
clamp now reports each managed focusable that crosses the edge, and it
replaces the font-load listener.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp's edge observer reports a link that lands exactly on the clip edge

A link whose top touches the edge intersects at ratio 0 but is clipped.
The observer now also reports at a threshold just above 0.

Co-authored-by: HelloOjasMutreja <[email protected]>

* Merge remote-tracking branch 'origin/main' into feat/lab-line-clamp

* fix(lab): LineClamp keeps a focusable with no layout box inert

A child can show a hidden link past the clip edge with no watched
change, so no pass runs. A candidate with no layout box now counts as
clipped; the edge observer releases it once it shows on a visible line.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp keeps a 0×0 focusable on a visible line reachable

The no-box test counted a 0×0 box (a visually hidden checkbox in its
label) as clipped. Only a candidate with no client rects at all counts
now, and a display: contents candidate is skipped, since its children
are the candidates.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp runs its pass on hidden, class and style changes instead of guessing at boxless links

The no-box rule kept a link inert after a class change turned it into
display: contents on a visible line. The clipping pass now uses the
plain geometry rule again, and a change to hidden, class or style inside
the clamp runs it, so a link shown or restyled with no other change is
measured where it is.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp judges a boxless link by its display, and decorative styling runs no pass

A display: none candidate has an all-zero rect, so the rect rule read it
as top 0: a link an ancestor outside the clamp showed past the edge was
never hidden, and a display: contents link was hidden whenever the clamp
sat above the viewport. A display: none candidate now stays inert until
the edge observer sees it on a visible line, and a display: contents
candidate is left to its children. A hidden, class or style change runs
the pass only on a candidate or an ancestor of one, so animation inside
the clamp reads no layout.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp leaves the controls of a popover or dialog inside it alone

A popover or dialog renders in the top layer, which the clamp does not
clip, so its controls are not the clamp's to hide. Ownership now stops
at that layer boundary.

Co-authored-by: HelloOjasMutreja <[email protected]>

* Merge remote-tracking branch 'origin/main' into feat/lab-line-clamp

* fix(lab): LineClamp leaves controls in an out-of-flow box it does not clip alone

An absolute or fixed element whose containing block is outside the
clamp, such as a menu panel that opens below it, is not clipped by the
clamp, so its controls are not the clamp's to hide. One whose
containing block is inside the clamp is still clipped and still hidden.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp follows one rule for what it makes inert

A focusable becomes inert only when it is in the clamp's own flow (no
absolute, fixed, top-layer or portal ancestor) and its box lies wholly
past the last visible line. Anything in a positioned subtree is never
made inert, at any depth, which replaces the containing-block walk. The
docs state the rule and its one gap.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp judges a control's positioned native input by its in-flow wrapper

CheckboxInput and Switch place their native input against their own
positioned wrapper, which sits in the clamp's flow, so the input never
became inert. An absolute box whose containing block is in the clamp's
flow now stays in the flow, and that block's box decides. A fixed box,
or an absolute box placed against the clamp or something outside it,
still starts a subtree that is never made inert. The docs state the
refined rule.

Co-authored-by: HelloOjasMutreja <[email protected]>

* fix(lab): LineClamp keeps a boxless positioned control inert

A display: none CheckboxInput or Switch has no offsetParent, so its
native input read as escaping the clamp and was released; a change
outside the clamp could then show it past the edge as a tab stop on an
invisible control. A boxless node now finds its containing block from
computed style, so it stays in the flow and stays inert until it gains
a box. The docs say so.

Co-authored-by: HelloOjasMutreja <[email protected]>

Co-authored-by: Cindy Zhang <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — ed494011 Deployed Aug 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants