Repository navigation
fix(core): render plain Link anchors inline so an ancestor Text clamp can truncate them - #6038
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @ManoharPaturi! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
There was a problem hiding this comment.
🟡 Changes recommended
The newly added CSS-introspection test helper matches selectors via substring checks, which can produce incorrect/flaky assertions and should be made selector-token-accurate.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates Link’s default anchor layout so it can be truncated by an ancestor <Text maxLines> clamp, while preserving inline-flex where it’s required (external-link icon and button-rendered form). Also adds documentation and tests to prevent regressions around the clamp behavior described in #6021.
Changes:
- Render plain
<a>links asdisplay: inline(instead ofinline-flex) to allow ancestor-webkit-line-clamptruncation. - Introduce a dedicated
flexLayoutstyle applied only to external-link icon and button-rendered forms. - Add docs + tests covering the truncation behavior and the external-link limitation.
File summaries
| File | Description |
|---|---|
| packages/core/src/Text/Text.doc.mjs | Documents that external-link Link children won’t be truncated by an ancestor Text maxLines. |
| packages/core/src/Link/Link.tsx | Switches base anchor display to inline and scopes inline-flex to icon/button cases via flexLayout. |
| packages/core/src/Link/Link.test.tsx | Adds tests asserting the emitted display mode for plain/external/button Link forms. |
| packages/core/src/Link/Link.doc.mjs | Adds Link guidance for when ancestor Text maxLines truncation will/won’t work. |
| .changeset/link-anchor-clamp.md | Publishes the behavioral change as a patch changeset for @astryxdesign/core. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| for (const chunk of getAllInjectedCss().split('}')) { | ||
| const sel = chunk.split('{')[0] ?? ''; | ||
| const body = chunk.split('{')[1] ?? ''; | ||
| if (classes.some(c => sel.includes(c)) && body.includes('display')) { | ||
| const match = body.match(/display:\s*([^;]+);/); | ||
| if (match) { | ||
| declarations.push(match[1].trim()); | ||
| } | ||
| } | ||
| } |
The displayDeclarationsFor helper added in meta#6038 matched an element's classList against raw selector text via String.includes, which is a substring check on hashed atomic class names (e.g. StyleX's x1a2b3c style classes). A shorter class name can be a substring of an unrelated longer one, so the check can both false-positive and false-negative depending on what else StyleX has generated for the test run. Rewrite it to walk the real CSSOM: parse each CSSStyleRule's selectorText into class tokens, compare those tokens against the element's classList by exact match, and read the declaration via rule.style.getPropertyValue('display') instead of a body-text regex. Also descends into grouping rules (e.g. @media) so nested declarations aren't missed. Flagged by Copilot review on meta#6038: meta#6038 (review) All 63 Link tests and 189 Text tests still pass; tsc --noEmit is clean.
|
Hey @ManoharPaturi, nice fix — the base/flexLayout split is exactly the right shape for this. I took a stab at the one thing Copilot flagged (the Ran it against your branch locally: all 63 Link tests, 189 Text tests, and 640 eslint-plugin-astryx tests still pass, and Opened it as a PR on top of your branch here: #6043 — happy to fold it directly into this PR instead if you'd rather take the diff yourself, just say the word. Wanted to flag it here first rather than just have a second PR show up with no context. |
cixzhang
left a comment
There was a problem hiding this comment.
Existing block Links lose keyboard focus visibility in this change. In Chromium, <Link display="block"> changes from a 124px inline-flex focus box to an inline anchor split around a 260px block child; the 2px focus outline computes but paints nothing. Please preserve the old focusable box for block/own-clamped Link variants while keeping only unclamped plain anchors inline.
[Reviewed by Robohands]
| // can truncate it. An inline-flex box establishes its own formatting | ||
| // context, which an ancestor -webkit-line-clamp cannot reach — | ||
| // <Text maxLines={2}><Link>…</Link></Text> silently did nothing. | ||
| display: 'inline', |
There was a problem hiding this comment.
display="block" now splits this inline anchor around its block child, so its keyboard focus outline disappears.
The displayDeclarationsFor helper added in meta#6038 matched an element's classList against raw selector text via String.includes, which is a substring check on hashed atomic class names (e.g. StyleX's x1a2b3c style classes). A shorter class name can be a substring of an unrelated longer one, so the check can both false-positive and false-negative depending on what else StyleX has generated for the test run. Rewrite it to walk the real CSSOM: parse each CSSStyleRule's selectorText into class tokens, compare those tokens against the element's classList by exact match, and read the declaration via rule.style.getPropertyValue('display') instead of a body-text regex. Also descends into grouping rules (e.g. @media) so nested declarations aren't missed. Flagged by Copilot review on meta#6038: meta#6038 (review) All 63 Link tests and 189 Text tests still pass; tsc --noEmit is clean.
|
@parinith-web thank you for this — the CSSOM-token matching is a real improvement over my substring approach (exact class comparison + proper descent into grouping rules), and I appreciate you flagging it here first rather than surprising us with a stacked PR. Folded your commit into this branch as 1abf92c (kept your authorship). #6043 can be closed whenever convenient — all 63 Link tests green on the updated branch. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for tightening the test helper. The earlier keyboard-focus regression is still present in Chromium: both <Link display="block"> and <Link maxLines={2}> compute a 2px outline but paint no visible focus box because the anchor remains inline around a block-level Text child. Please preserve a visible root focus box for those forms while keeping only the ancestor-clamped plain anchor inline.
[Reviewed by Robohands]
|
Thanks @cixzhang — fixed in 2a36cb1. The inline anchor is now reserved for the one composition this PR exists for: the unclamped plain Link under an ancestor
So Two new test cases assert the block and self-clamped forms keep |
|
/approve-spec 2b66bd4 |
There was a problem hiding this comment.
Inside a clamped <Text maxLines> a default Link now truncates with the text in Chromium and shows its inset focus ring on each visible line, Links outside a clamp render exactly as before, and the Link and Text record changes have an engineering owner's approval for this head. One wording fix is needed before approval.
- The changeset says the clamp does not clip the focus ring and the new Chromium test calls it the whole ring, but the test checks only the ring's top and bottom edges and a one-line clamp cuts its end edge, so please narrow both to the edges that stay visible.
The branch also conflicts with main in Link.spec.md and Link.test.tsx; the rebase should keep FR6's label-colour clause from main, and the rebased head needs a fresh /approve-spec from an engineering owner. The engineering owner's change request from 2026-09-05 stands until they re-review or dismiss it, and CI has not run on this head yet: a maintainer adds the ci:run label so it runs.
[Automated review]
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] Link: inside a `<Text maxLines>` the link now truncates with the text. There its root lays out inline, in the text's lines, so the clamp can cut through the link, and its keyboard focus ring sits inside each line so the clamp does not clip it. Elsewhere, and for a Link that sets its own `display` or `maxLines` or renders as a button, the root keeps its `inline-flex` box. (#6021) |
There was a problem hiding this comment.
This promises more than the head delivers: in <Text maxLines={1}> a Link longer than the line keeps its start, top and bottom ring edges, but the clamp cuts the end edge with the text (Chromium). Suggested ending for the sentence: …so the clamp can cut through the link, and its keyboard focus ring is inset into each line, so the clamp keeps its top and bottom edges.
| ['ancestor-clamp-text', 1], | ||
| ['ancestor-clamp-one-line', 2], | ||
| ] as const) { | ||
| test(`${testId}: a Link inside the clamp paints its whole keyboard focus ring`, async ({ |
There was a problem hiding this comment.
The test samples only the top and bottom edges (lines 125-126), and in the one-line case the ring's end edge is clipped, so "whole" overstates what it proves. Suggested title: a Link inside the clamp paints the top and bottom of its keyboard focus ring, with the header at line 7 to match.
| // sits inside each line box. | ||
| inClampedText: { | ||
| display: 'inline', | ||
| outlineOffset: `calc(-1 * ${focusVars['--focus-outline-width']})`, |
There was a problem hiding this comment.
Non-blocking, for design review: inset by its own width, the ring is drawn over the text, so on a clamped line its end edge crosses the ellipsis (team… reads team.|. in ClampedByAncestorText) and it touches the last glyph of each line.
# Conflicts: # docs/specs/components/Link/Link.spec.md # packages/core/src/Link/Link.test.tsx
|
/approve-spec 6237f98 |
There was a problem hiding this comment.
Changes requested: inside a clamped <Text maxLines> a default Link now truncates with the text and keeps a visible inset focus ring, and the component:Link FR6 and component:Text record changes carry an engineering owner's approval for this head, so one release-note fix remains.
- Miss:
.changeset/link-anchor-clamp.mdsays the link "now truncates with the text" inside a clamp, but a Link with block-level content (such as anHStackwith an icon) there now breaks the clamp and shows no focus ring wheremainclamped it, so please add one sentence saying that composition is not supported inside a clamped Text and belongs outside the clamp.
After that fix, the engineering owner's 2026-09-05 change request about block-child focus rings still needs a re-review or dismissal, and CI runs once a maintainer adds the ci:run label.
[Automated review]
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] Link: inside a `<Text maxLines>` the link now truncates with the text. There its root lays out inline, in the text's lines, so the clamp can cut through the link, and its keyboard focus ring is inset into each line, so the clamp keeps the ring's top and bottom edges visible. Elsewhere, and for a Link that sets its own `display` or `maxLines` or renders as a button, the root keeps its `inline-flex` box. (#6021) |
There was a problem hiding this comment.
Miss: this says the link "now truncates with the text" inside a <Text maxLines>, but a Link with block-level content, such as an HStack with an icon, now breaks the clamp there (three lines instead of two in a 220px column) and paints no focus ring, where main clamped it and showed part of its ring. Please add one sentence, for example: "A Link with block-level content, such as an HStack with an icon, is not supported inside a clamped Text: it now breaks the clamp and shows no focus ring, so place it outside the clamp."
…inside a clamped Text
|
/approve-spec 357e9cf |
There was a problem hiding this comment.
Changes requested: inside a clamped <Text maxLines> a default Link now truncates with the text and keeps an inset focus ring, the changeset now says block-level Link content is unsupported there, and the component:Link FR6 and component:Text record changes carry an engineering owner's approval for this head, so one lint fix remains.
- Miss: the required
lintcheck runs ESLint in strict mode, which fails onpackages/core/src/Text/Text.tsx:283(the comment cites the record claim "(FR4)"; drop the citation) and onpackages/core/src/Text/Text.test.tsx:447and:458(an unnecessaryas HTMLInputElement; writescreen.getByRole<HTMLInputElement>('textbox', {name: 'Note'})as other core tests do).
After that fix, the engineering owner's 2026-09-05 change request about block-child focus rings still needs a re-review or dismissal, and CI runs once a maintainer adds the ci:run label.
[Automated review]
| // Keep the merged ref stable across rerenders. | ||
| const mergedRef = useMergedRefs(ref, truncation.ref, textRef); | ||
| const isInClampedText = use(TextClampContext); | ||
| // A capsize block removes a multi-line clamp (FR4). |
There was a problem hiding this comment.
Strict ESLint, which the required lint check runs (CI=true), fails here with @astryx/no-comment-provenance: "FR4 cites a record claim". Suggested:
// A capsize block removes a multi-line clamp.| const input = screen.getByRole('textbox', { | ||
| name: 'Note', | ||
| }) as HTMLInputElement; |
There was a problem hiding this comment.
Strict ESLint fails here and at line 458 with @typescript-eslint/no-unnecessary-type-assertion. Passing the element type keeps input.value typed and passes lint and the core typecheck:
const input = screen.getByRole<HTMLInputElement>('textbox', {
name: 'Note',
});The same applies to after at line 458.
…omment, type getByRole, no non-null assertions in the Chromium spec
|
/approve-spec 4eb64fd |
There was a problem hiding this comment.
Not approved yet, although nothing in the code needs to change: inside a clamped <Text maxLines> a default Link now truncates with the text and keeps an inset focus ring, the strict-lint errors from the last round are fixed, and the component:Link FR6 and component:Text record changes carry an engineering owner's /approve-spec for this head.
- The engineering owner's change request from 2026-09-05 (Links with a block-level child must keep a visible focus ring) is still their latest review on this pull request, so approval waits on that owner re-reviewing, or a maintainer dismissing it, now that FR6 declares block-level Link content unsupported inside a clamp.
CI has not run on this head yet: a maintainer adds the ci:run label so it runs.
[Automated review]
|
/approve-spec d82bb84 |
There was a problem hiding this comment.
Not approved yet, although nothing in the code needs to change: inside a clamped <Text maxLines> a default Link now truncates with the text and keeps an inset focus ring, Links outside a clamp render exactly as before, and the component:Link FR6 and component:Text record changes carry an engineering owner's /approve-spec for this head. CI passes, including the new Chromium clamp spec.
What remains is not a code change: the engineering owner's change request from 2026-09-05 (Links with a block-level child must keep a visible focus ring) is still their latest review on this pull request. This head keeps that ring outside a clamp and declares block-level content inside a clamped Text unsupported, so that owner re-reviews, or a maintainer dismisses the request.
- Non-blocking, for design: the inset ring draws over the text, so on a clamped line its end edge can meet the ellipsis.
[Automated review]
cixzhang
left a comment
There was a problem hiding this comment.
Approving at this exact head. The 09/04–09/05 review's three requested outcomes are each mapped to evidence in the PR body ("09/04–09/05 review → where it's addressed"), and the automated review at this head found nothing in the code to change. Posted by Cindy's agent on her behalf.
There was a problem hiding this comment.
Approved. Inside a clamped <Text maxLines>, a default Link now truncates with the text and keeps an inset keyboard focus ring on each visible line, Links outside a clamp render exactly as before, and the component:Link FR6 and component:Text record changes carry an engineering owner's approval for this head. CI passes, including the new Chromium clamp spec.
- Non-blocking, for design: the inset ring draws over glyph edges, so on a clamped line its end edge can meet the ellipsis.
[Automated review]
Fixes #6021
09/04–09/05 review → where it's addressed
Checked at head
4eb64fda, in real Chromium against this head's Storybook build and main's, keyboard focus by Tab, the ring found by diffing the painted pixels before and after focus.<Link display="block">keeps a visible focus boxinline-flexand paints the shared 2px ring around the link, the same pixels as on main. Inside a clamped Text a Link that setsdisplaykeeps its own box: testLink display › keeps its own box inside a clamped Text when it sets display or maxLines.<Link maxLines>keeps a visible focus boxmaxLines={2}and a two-line label at 320px, the root staysinline-flexand the ring paints around both lines, the same pixels as on main. Inside a clamped Text: the same test as (1).HStackand an icon) stay visibly focused; only text-only ancestor-clamped Links go inlineinline-flexand paints the whole ring around the row, the same pixels as on main. TestLink.ancestor-clamp.a11y.chromium.spec.ts › a composed Link keeps its box and paints a keyboard focus outline. Inside a clamped Text, block-level content is not supported, because it breaks the clamp (component:LinkFR6,component:Text); the changeset and the Link docs say so. A text Link inside a one- or two-line clamp shows the top and bottom edges of its inset ring: the two… shows the top and bottom edges of its keyboard focus ringtests in the same spec.Summary
A plain
<Text maxLines={2}><Link>…</Link></Text>did not truncate. The anchor wasdisplay: inline-flex, an atomic inline box that an ancestor-webkit-line-clampcannot cut.Now a Link inside a clamped Text lays out
inline, in the text's line boxes, so the clamp truncates it. Link decides from the enclosing Text's clamp, never from its own children (the Link record's AV1):maxLines > 0provides a layer-scoped clamp context. A layer opened inside the text resets it, because a layer is not inside the clamped box.displayand nomaxLinesof its own usesdisplay: inline. The external-link icon keeps its gap with an inline margin.inline-flexbox, unchanged: outside a clamp, with its owndisplayormaxLines, or in the button form. So the wrapped-lines layout and the focus box of composed links outside a clamp do not change.The Link record's FR6 gap ("the root is
inline-flex, so an ancestor Text clamp does not truncate it") is closed, and FR6 states the rule.Tests
Link.test.tsx: the display per case, from the injected CSS.displayormaxLines, in the button form, and in a layer inside the clamp.Link.ancestor-clamp.a11y.chromium.spec.ts: in real Chromium, the clamp cuts through the link, and a composed Link outside a clamp keeps its box and paints a focus outline.Testing
vitest run packages/core/src/Link packages/core/src/Text: 425 of 425 pass at ca713fe, including the newmaxLinestoggle test (same element, value and focus across 2 → 0 → 2) and the Link clamp-display cases.Link.ancestor-clamp2 of 2 pass (the clamp cuts through the link; a composed Link outside a clamp keeps its box and focus outline), andLink.wrappedLines3 of 3 pass, unchanged.Reshaped by a maintainer per the AV1 ruling: the earlier children inspection is replaced by the clamp context. The original commits and credit are kept.