Repository navigation
fix(Text, Heading): a truncated label shows one tooltip, not two - #5559
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsHeading (@astryxdesign/core) · View in Storybook
Text (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 2 accessibility violation(s) found — 2 serious. Heading - 1 issue(s)
Text - 1 issue(s)
Visual RegressionStatus: 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 |
cixzhang
left a comment
There was a problem hiding this comment.
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]
…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.
…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.
…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.
…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.
…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.
…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.
…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.
…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.
* 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]>
Summary
A truncated
Textrenders Astryx'sTooltipand sets the nativetitleattribute to the same string — both gated on the sametooltipEnabled. 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
titlepresence plus a count of visible[role="tooltip"]elements after hover:Why the
titlegoes and not theTooltipTooltipalready carries the a11y contract. It setsaria-describedbyon its anchor (Tooltip.tsx:253-256), verified still present after this change.titlewas not what made the truncated text readable to a screen reader.titleis 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
Textcarries notitle. 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.title(checked before removing it).Note
Badgegains the same tooltip in a follow-up; it will use theTooltipalone rather than reintroducing this pair.@freddymeta