Repository navigation
feat(lab): add LineClamp — clamp arbitrary content to N lines - #4259
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Visual before/after, verified against the live Storybook story: Text, font, size, color, and line height come directly from the running story (Lab/LineClamp, Default), not typed by hand. The tooltip on hover/focus is a real feature of the component, shown here as a static capture; try it live in Storybook to see it appear on hover. |
a868309 to
d96fa86
Compare
|
Rebased onto the latest main (was a few days behind). CI should be green again. Happy to address any feedback or make adjustments -- let me know if anything needs changing before this can move forward. |
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/LineClamp · Storybook | 13.3 kB (new) · 168 B CSS (new) | 383 (new) | — · ✓ · ✗ |
| lab/PageControl | 73.1 kB (+65 B) · 709 B CSS (0) | — | — · — · — |
| ContextMenu | 106.3 kB (+51 B) · 17.0 kB CSS (0) | — | — · — · — |
109 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| charts/ChartLegend | 48.4 kB (+50 B) · 224 B CSS (0) | — | — · — · — |
| BottomSheet | 65.6 kB (+50 B) · 7.5 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 250.8 kB (+49 B) · 454 B CSS (0) | — | — · — · — |
| lab/TransferListSelector | 113.1 kB (+47 B) · 1.9 kB CSS (0) | — | — · — · — |
| Drawer | 49.3 kB (+46 B) · 8.2 kB CSS (0) | — | — · — · — |
| Switch | 100.7 kB (+46 B) · 9.9 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 107.0 kB (+46 B) · 17.2 kB CSS (0) | — | — · — · — |
| richtext/RichTextView | 274.9 kB (+46 B) · 2.3 kB CSS (0) | — | — · — · — |
| DateInput | 182.7 kB (+45 B) · 16.7 kB CSS (0) | — | — · — · — |
| DateTimeInput | 204.5 kB (+45 B) · 18.4 kB CSS (0) | — | — · — · — |
| DropdownMenu | 95.6 kB (+45 B) · 17.1 kB CSS (0) | — | — · — · — |
| Heading | 11.8 kB (+45 B) · 5.4 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditor | 295.6 kB (+45 B) · 2.6 kB CSS (0) | — | — · — · — |
| charts/ChartTooltip | 174.8 kB (+44 B) · 423 B CSS (0) | — | — · — · — |
| SegmentedControlItem | 17.3 kB (+44 B) · 4.3 kB CSS (0) | — | — · — · — |
| TableCell | 107.5 kB (+44 B) · 17.4 kB CSS (0) | — | — · — · — |
| Tokenizer | 90.1 kB (+44 B) · 18.4 kB CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 103.5 kB (+44 B) · 1.1 kB CSS (0) | — | — · — · — |
| lab/ListInput | 100.4 kB (+44 B) · 1.6 kB CSS (0) | — | — · — · — |
| BreadcrumbItem | 83.3 kB (+43 B) · 12.0 kB CSS (0) | — | — · — · — |
| CommandPalette | 72.4 kB (+43 B) · 12.4 kB CSS (0) | — | — · — · — |
| FileInput | 68.0 kB (+43 B) · 10.8 kB CSS (0) | — | — · — · — |
| RadioListItem | 66.1 kB (+43 B) · 10.1 kB CSS (0) | — | — · — · — |
| Spinner | 24.1 kB (+43 B) · 6.2 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 330.1 kB (+43 B) · 2.4 kB CSS (0) | — | — · — · — |
| AlertDialog | 104.1 kB (+42 B) · 14.3 kB CSS (0) | — | — · — · — |
| MoreMenu | 95.9 kB (+42 B) · 17.1 kB CSS (0) | — | — · — · — |
| Selector | 98.2 kB (+42 B) · 17.1 kB CSS (0) | — | — · — · — |
| StackItem | 16.3 kB (+42 B) · 219 B CSS (0) | — | — · — · — |
| ChatComposer | 76.7 kB (+41 B) · 12.0 kB CSS (0) | — | — · — · — |
| InputGroup | 55.4 kB (+41 B) · 7.8 kB CSS (0) | — | — · — · — |
| Link | 52.0 kB (+41 B) · 7.0 kB CSS (0) | — | — · — · — |
| Pagination | 108.3 kB (+41 B) · 17.5 kB CSS (0) | — | — · — · — |
| DateRangeInput | 91.1 kB (+40 B) · 12.4 kB CSS (0) | — | — · — · — |
| LayoutContent | 17.7 kB (+40 B) · 1.7 kB CSS (0) | — | — · — · — |
| TopNavMenu | 73.4 kB (+40 B) · 11.2 kB CSS (0) | — | — · — · — |
| lab/DiffViewer | 85.5 kB (+40 B) · 2.1 kB CSS (0) | — | — · — · — |
| lab/TransferList | 106.4 kB (+40 B) · 1.7 kB CSS (0) | — | — · — · — |
| Banner | 61.1 kB (+39 B) · 10.4 kB CSS (0) | — | — · — · — |
| Button | 59.1 kB (+39 B) · 9.9 kB CSS (0) | — | — · — · — |
| ChatToolCalls | 31.4 kB (+39 B) · 8.3 kB CSS (0) | — | — · — · — |
| CheckboxList | 68.0 kB (+39 B) · 8.1 kB CSS (0) | — | — · — · — |
| CommandPaletteInput | 31.0 kB (+39 B) · 7.5 kB CSS (0) | — | — · — · — |
| ComplexSelector | 69.7 kB (+39 B) · 11.7 kB CSS (0) | — | — · — · — |
| DropdownMenuSubMenu | 69.0 kB (+39 B) · 9.7 kB CSS (0) | — | — · — · — |
| HoverCard | 26.4 kB (+39 B) · 4.4 kB CSS (0) | — | — · — · — |
| Lightbox | 117.8 kB (+39 B) · 10.4 kB CSS (0) | — | — · — · — |
| MobileNav | 69.4 kB (+39 B) · 10.5 kB CSS (0) | — | — · — · — |
| TableSelectionToolbar | 69.3 kB (+39 B) · 13.1 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 102.4 kB (+39 B) · 773 B CSS (0) | — | — · — · — |
| SideNavHeading | 74.4 kB (+38 B) · 11.2 kB CSS (0) | — | — · — · — |
| Slider | 106.1 kB (+38 B) · 8.8 kB CSS (0) | — | — · — · — |
| TextArea | 61.1 kB (+38 B) · 9.3 kB CSS (0) | — | — · — · — |
| Timestamp | 32.3 kB (+38 B) · 10.2 kB CSS (0) | — | — · — · — |
| TopNav | 71.2 kB (+38 B) · 10.8 kB CSS (0) | — | — · — · — |
| lab/Schedule | 104.5 kB (+38 B) · 3.9 kB CSS (0) | — | — · — · — |
| AppShell | 89.6 kB (+37 B) · 13.4 kB CSS (0) | — | — · — · — |
| CheckboxInput | 63.2 kB (+37 B) · 9.1 kB CSS (0) | — | — · — · — |
| CheckboxListItem | 69.8 kB (+37 B) · 11.3 kB CSS (0) | — | — · — · — |
| Field | 53.7 kB (+37 B) · 7.2 kB CSS (0) | — | — · — · — |
| MultiSelector | 93.5 kB (+37 B) · 16.6 kB CSS (0) | — | — · — · — |
| SideNav | 110.9 kB (+37 B) · 11.3 kB CSS (0) | — | — · — · — |
| TextInput | 66.5 kB (+37 B) · 11.1 kB CSS (0) | — | — · — · — |
| Toast | 97.0 kB (+37 B) · 10.2 kB CSS (0) | — | — · — · — |
| Typeahead | 78.4 kB (+37 B) · 12.4 kB CSS (0) | — | — · — · — |
| lab/Comments | 337.1 kB (+37 B) · 2.5 kB CSS (0) | — | — · — · — |
| lab/SelectableCardGroup | 63.1 kB (+37 B) · 162 B CSS (0) | — | — · — · — |
| Calendar | 70.2 kB (+36 B) · 10.5 kB CSS (0) | — | — · — · — |
| ChatComposerInput | 74.4 kB (+36 B) · 11.2 kB CSS (0) | — | — · — · — |
| ChatComposerTokenElement | 74.4 kB (+36 B) · 11.2 kB CSS (0) | — | — · — · — |
| CodeBlock | 73.8 kB (+36 B) · 11.2 kB CSS (0) | — | — · — · — |
| DialogHeader | 62.0 kB (+36 B) · 11.4 kB CSS (0) | — | — · — · — |
| IconButton | 59.2 kB (+36 B) · 9.9 kB CSS (0) | — | — · — · — |
| InfoTip | 45.4 kB (+36 B) · 5.3 kB CSS (0) | — | — · — · — |
| LayoutPanel | 21.0 kB (+36 B) · 4.9 kB CSS (0) | — | — · — · — |
| Markdown | 179.5 kB (+36 B) · 20.0 kB CSS (0) | — | — · — · — |
| RadioList | 55.1 kB (+36 B) · 7.2 kB CSS (0) | — | — · — · — |
| Text · Storybook | 11.2 kB (+36 B) · 5.4 kB CSS (0) | 714 (0) | ✓ · ✓ · — |
| Timer | 13.3 kB (+36 B) · 6.0 kB CSS (0) | — | — · — · — |
| ButtonGroup | 41.5 kB (+35 B) · 3.7 kB CSS (0) | — | — · — · — |
| ChatDictationButton | 59.7 kB (+35 B) · 10.0 kB CSS (0) | — | — · — · — |
| ChatLayoutScrollButton | 59.6 kB (+35 B) · 10.1 kB CSS (0) | — | — · — · — |
| ChatSendButton | 59.5 kB (+35 B) · 9.9 kB CSS (0) | — | — · — · — |
| NumberInput | 70.5 kB (+35 B) · 11.3 kB CSS (0) | — | — · — · — |
| Stepper | 60.8 kB (+35 B) · 10.0 kB CSS (0) | — | — · — · — |
| Table | 116.4 kB (+35 B) · 17.7 kB CSS (0) | — | — · — · — |
| TimeInput | 158.4 kB (+35 B) · 15.7 kB CSS (0) | — | — · — · — |
| TopNavHeading | 73.8 kB (+35 B) · 11.0 kB CSS (0) | — | — · — · — |
| TopNavMegaMenu | 68.5 kB (+35 B) · 11.7 kB CSS (0) | — | — · — · — |
| BaseTypeahead | 70.0 kB (+34 B) · 10.8 kB CSS (0) | — | — · — · — |
| ChatLayout | 79.3 kB (+34 B) · 10.4 kB CSS (0) | — | — · — · — |
| FieldLabel | 49.8 kB (+34 B) · 5.7 kB CSS (0) | — | — · — · — |
| Thumbnail | 63.5 kB (+34 B) · 11.5 kB CSS (0) | — | — · — · — |
| ToggleButton | 60.0 kB (+34 B) · 10.0 kB CSS (0) | — | — · — · — |
| DrawerHeader | 62.1 kB (+33 B) · 12.8 kB CSS (0) | — | — · — · — |
| SideNavItem | 69.3 kB (+33 B) · 11.0 kB CSS (0) | — | — · — · — |
| Dialog | 23.7 kB (+32 B) · 6.7 kB CSS (0) | — | — · — · — |
| charts/Chart | 197.6 kB (+31 B) · 494 B CSS (0) | — | — · — · — |
| TabMenu | 70.6 kB (+31 B) · 11.0 kB CSS (0) | — | — · — · — |
| ListItem | 68.7 kB (+30 B) · 11.3 kB CSS (0) | — | — · — · — |
| MobileNavToggle | 59.4 kB (+30 B) · 9.9 kB CSS (0) | — | — · — · — |
| SideNavCollapseButton | 59.9 kB (+30 B) · 10.0 kB CSS (0) | — | — · — · — |
| ChatMessageList | 27.5 kB (+29 B) · 7.0 kB CSS (0) | — | — · — · — |
| Popover | 87.9 kB (+29 B) · 13.9 kB CSS (0) | — | — · — · — |
| lab/EmojiPicker | 85.1 kB (+29 B) · 751 B CSS (0) | — | — · — · — |
| lab/TourStep | 94.2 kB (+28 B) · 590 B CSS (0) | — | — · — · — |
| lab/CommentComposer | 147.2 kB (+27 B) · 1.9 kB CSS (0) | — | — · — · — |
| Carousel | 68.6 kB (+26 B) · 10.8 kB CSS (0) | — | — · — · — |
| PowerSearch | 282.4 kB (+24 B) · 23.6 kB CSS (0) | — | — · — · — |
Package size:
- @astryxdesign/cli 3.52 MB packed (+10 B); no new dependencies
- @astryxdesign/core 6.99 MB packed (+1.2 kB); no new dependencies
API changes: none in this pull request
Committed API report behind this build: cli 29 rows, core 35 rows; run pnpm api:report.
Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
|
Thanks @HelloOjasMutreja for working on this! Sorry we hadn't fully fleshed out the spec. The line clamp component works a bit differently internally but this is a good start. We have a "See more"/"See less" link at the end of the clamp. Here's a video of the behavior. Screen.Recording.2026-07-27.at.6.23.06.PM.movWe're using a resize observer at the moment to check for overflow to display the see more/see less toggles, but there may be a better way to do this with modern CSS (haven't explored yet). Let me know if you'd be down to update it to work this way! Otherwise, since this is a lab component we can accept it and adjust forward on my side. For the time being, there's one test failure but this was resolved on main recently so you jsut need to rebase to get the green CI. |
d96fa86 to
936e55e
Compare
|
@cixzhang Rebased onto current main again to clear the CI failure you flagged — that test was already fixed there, so this should be green now. Happy to take on the See more/See less + resize-observer rework if you'd like — let me know and I'll pick it up as a follow-up. Otherwise this is ready to land as-is and I'll leave the iteration to you, whichever you'd prefer. |
f8716b6 to
c4ec3d1
Compare
|
@HelloOjasMutreja is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — I’d already said the lab shape can iterate, and the clamp/mixed-content paths work. Two current-main regressions need fixing before merge.
Clamped content mounts Astryx's Tooltip and sets the same native title, so hover shows the full text twice. Text and Heading just removed that pairing in #5559.
mergeRefs(...) is also recreated every render. One rerender called a consumer ref four times (null/node twice), while Text's useMergedRefs control called it zero; that also re-registers truncation measurement.
Could you carry over those two current Text patterns? If you'd rather talk it through with someone, we're in Discord.
| Current Text control | LineClamp at this head |
|---|---|
![]() |
![]() |
[Reviewed by Robohands]
|
Pushed 4a5eba7 with both patterns carried over from #5559:
Verified against |
cixzhang
left a comment
There was a problem hiding this comment.
This head fixes both blockers from my prior review: the duplicate native title is gone, and the consumer ref stays attached across rerenders.
The remaining public contract can strand keyboard users. In Chromium, a fully clipped link was the next Tab stop; focusing it scrolled the clamp 72px and replaced the visible line with the hidden action. Clamped content needs a predictable keyboard path with no invisible focusable descendants or focus-triggered content swap.
[Reviewed by Robohands]
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]>
|
/approve-spec 3cf7835 |
There was a problem hiding this comment.
Changes requested: one keyboard defect remains in LineClamp's clipping pass. A link a child reveals past the clip edge now stays out of the Tab order, and the engineering owner's approval at this commit settles the component's contract.
- A focusable rendered at 0×0 on a visible line, such as a visually hidden checkbox inside its label (
opacity: 0; width: 0; height: 0) or adisplay: contentswrapper with atabindex, is now markedinertfor good by the 0×0 test atLineClamp.tsx:134, so keyboard and screen reader users cannot reach it; testingel.getClientRects().length === 0for "no box", skippingdisplay: contentscandidates and adding a test for each would fix it.
Optional polish: read every rect before the first inert write in the clipping pass, and shorten the long source comments flagged inline earlier.
[Automated review]
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]>
|
/approve-spec 1be18ac |
There was a problem hiding this comment.
Changes requested: one keyboard and screen-reader defect remains in LineClamp's clipping pass. The 0×0 checkbox from the last review now stays reachable, a display: contents wrapper is left to its children, and the engineering owner's approval at this commit settles the component's contract.
- A focusable that becomes
display: contentsafter LineClamp marked itinert(for example a link shown by removing adisplay: noneclass, or atabindexwrapper that turnsdisplay: contentsas the box widens) keepsinerton a visible line, because the new skip atLineClamp.tsx:132runs before the release branch, so its text ignores clicks and leaves the accessibility tree and its inner links drop out of the Tab order; releasing a marked candidate before the skip (if (el.hasAttribute(HIDDEN_ATTRIBUTE)) restoreFromClip(el);), making the reveal of a marked boxless candidate run a pass (a class change alone runs none today), and adding a test for a link that goes fromdisplay: nonetodisplay: contentson a visible line would fix it.
Optional polish: read every candidate's style and rect before the first inert write, and shorten the long source comments flagged inline earlier.
[Automated review]
…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]>
|
/approve-spec 4efa57d |
There was a problem hiding this comment.
Changes requested: three defects remain in LineClamp's clipping pass. The previous blocker is fixed (a focusable the clamp marked that turns display: contents is released, and a link shown past the edge by removing hidden becomes inert), and the engineering owner's approval at this commit settles the component's contract.
- A link that a change outside the clamp shows past the edge (for example a class on an ancestor) is never made
inert, because adisplay: nonecandidate reads as top 0 and the pass now relies onhidden,classandstylechanges inside the clamp, so with the tooltip off the first Tab focuses a link nobody can see (LineClamp.tsx:130); keeping a candidate with no client rectsinertuntil the edge observer reports it on a visible line, as the previous commit did, would fix it. - Miss: a
display: contentslink on a visible line is madeinertby any pass that runs while the clamp is scrolled above the viewport (its empty rect reads top 0 against a negative bottom) and stays inert after scrolling back, so clicks on it do nothing and screen readers lose it until the next render, whether the clamp truncates or not (LineClamp.tsx:130); skipping adisplay: contentscandidate and releasing any marker it holds would fix it. - Any inline-style or class animation inside the clamp now runs the clipping pass twice per frame (124 passes and 248
getBoundingClientRectreads in one second for a decorative span animated byrequestAnimationFrame), becauseclassandstylerecords run the pass and also re-arm the edge observer (LineClamp.tsx:172-192); running the pass for those records only when the target is or contains a managed focusable, without re-arming the observer, would fix it.
Please add a test for each case. Optional: read every rect before the first inert write, and see the earlier comment-style notes.
[Automated review]
…ive 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]>
|
/approve-spec 89a6212 |
There was a problem hiding this comment.
Changes requested: one defect remains in LineClamp's clipping pass.
- Miss: a
Popoverplaced inside a clamp renders inside it (Core keeps layers inline under adiv) in the top layer, whichoverflow: clipdoes not clip, yet the clipping pass (LineClamp.tsx:144-147) makes every popover control at or below the clamp's bottom edgeinert, so Duplicate and Delete ignore clicks and Tab; stopping ownership at a layer boundary inisOwnedBy(for exampleclosest('[data-line-clamp-root], [popover], dialog')), with a test that opens a popover inside a clamp, would fix it.
The engineering owner's /approve-spec for this head settles the component's contract, and the earlier review points are fixed. The failing pr-interaction (2/6) SnapPaging case is not caused by this change; updating the branch onto main picks up its fix. The comment-style notes from earlier inline comments stay optional.
[Automated review]
… 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]>
|
/approve-spec 7d6cdc5 |
There was a problem hiding this comment.
Changes requested: one defect remains in LineClamp's clipping pass.
- Miss: a control the clamp does not clip is made
inertwhen it is positioned out of flow below the clamp: in Chromium, a disclosure menu whose panel isposition: absoluteopens below a two-line clamp, and its Share and Report links ignore clicks and Tab (LineClamp.tsx:149-152); skipping candidates that sit inside anabsoluteorfixedelement whose containing block is outside the clamp (or making the clamp root that containing block), with a test, would fix it.
The Popover and Dialog fix works: their controls stay clickable and tabbable inside a clamp, and a new test pins the Popover case. The engineering owner's /approve-spec for this head settles the component's contract. CI has no failing check so far; some jobs were still running when this review finished. The comment-style notes from earlier inline comments stay optional.
[Automated review]
… 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]>
|
/approve-spec 0311acc |
There was a problem hiding this comment.
Changes requested: one defect remains in LineClamp's clipping pass.
- A control positioned inside a menu panel that escapes the clamp is still made
inert:escapesClipstops at the innermostabsolutebox (LineClamp.tsx:180-182), so in Chromium a panel's absolutely placed Close button and a submenu's links ignore clicks and Tab; keep walking up when that box'soffsetParentis inside the clamp, and add a test with a positioned control inside the escaping panel.
The out-of-flow fix works for a panel's own links: Edit, Share and More stay clickable and tabbable, and the new test pins that case. The engineering owner's /approve-spec for this head settles the component's contract. CI has no failing check so far; some jobs were still running when this review finished. The comment-style notes from earlier inline comments stay optional.
[Automated review]
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]>
|
/approve-spec 93d98c3 |
There was a problem hiding this comment.
Changes requested: one defect remains in LineClamp's clipping pass.
- Core's
CheckboxInputandSwitchstay keyboard-focusable while the clamp hides them:isInPositionedSubtree(LineClamp.tsx:171-183) never makes aposition: absolutefocusable inert, and both controls render their native input that way inside their own positioned wrapper, so in Chromium Tab lands on a hidden checkbox and then a hidden switch (WCAG 2.4.7 and 2.4.11); deciding by containing block instead (skip a candidate only when afixedbox, or anabsolutebox whoseoffsetParentis outside the clamp, sits between it and the clamp) fixes it, keeps the escaping-panel cases working, and needs a test with an absolute input inside a positioned wrapper.
The escaping-panel fix works: a positioned Close button inside a menu panel that escapes the clamp is now reachable, and the new test pins it. The engineering owner's /approve-spec for this head settles the component's contract; the fix changes the documented inert rule, so it needs recording again on the head that carries it. CI passes at this head.
[Automated review]
… 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]>
|
/approve-spec a98b661 |
There was a problem hiding this comment.
Changes requested: one defect remains in LineClamp's clipping pass.
- A Core
CheckboxInputorSwitchthat is hidden (display: none) when the clamp checks is released, becauseflowBox(LineClamp.tsx:187-189) reads itsnulloffsetParentas escaping the clamp, so once a change outside the clamp shows it past the edge, Tab lands on the invisible input (WCAG 2.4.7 and 2.4.11); finding the containing block from computed style when the node has no box keeps itinert, and a test with a hiddenCheckboxInputthat a change outside the clamp reveals would pin it.
The containing-block rule fixes the previous finding: Core's checkbox and switch below the edge are now inert, they stay reachable on a visible line, and an escaping menu panel's controls still work. The engineering owner's /approve-spec for this head settles the component's contract. CI has no failing check at this head.
[Automated review]
| * starts such a subtree. An `absolute` box placed against a containing block | ||
| * in the clamp's flow (a control's own positioned wrapper) stays in the flow, | ||
| * and that containing block's box decides. A popover or dialog stops |
There was a problem hiding this comment.
Non-blocking (comment style): this sentence runs 27 words with two topics. Suggested: "An absolute box placed against an in-flow block in the clamp stays in the flow. That block's box decides, as for a control's own wrapper."
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]>
|
/approve-spec 05a28c4 |
There was a problem hiding this comment.
Approved pending CI: CI is still running on this head.
The last review's finding is fixed: a hidden Core CheckboxInput or Switch now stays inert when a change outside the clamp shows it past the edge, and the new test fails on the previous code. The engineering owner's /approve-spec for this head settles the component's contract.
Two non-blocking notes:
- An author's
position: absolutecontrol inside a transformed (orfilter,contain,will-change) wrapper is still a Tab stop when it is hidden at the check and later shown past the edge, because the walk for a node with no box looks only atposition; the doc already leaves positioned content to the author, so naming this case there, or re-checking such a control once it gains a box, would close it. flowBox's doc comment now sits above the newcontainingBlock(LineClamp.tsx:166-174); moving it back aboveflowBoxkeeps each function described.
[Automated review]
| ancestor != null; | ||
| ancestor = ancestor.parentElement | ||
| ) { | ||
| if (getComputedStyle(ancestor).position !== 'static') { |
There was a problem hiding this comment.
Non-blocking: transform, filter, contain and will-change also make a containing block, and Chromium resolves transform to none on an element with no box, so this walk cannot see them. In Chromium, an author's position: absolute link inside a transform: translateX(0) wrapper past the edge is inert when it has a box at the check, but when it is hidden at the check and then shown by a change outside the clamp, Tab lands on it while it is clipped (top 152, clamp bottom 104). The doc leaves positioned content to the author, so naming this case in its gap sentence, or re-judging a box-less candidate once it gains a box, would close it.
| /** | ||
| * The box whose position decides whether `el` is cut off, or null when `el` | ||
| * starts or sits in a subtree that is never made inert. A `fixed` box, or an | ||
| * `absolute` box whose containing block is the clamp or lies outside it, | ||
| * starts such a subtree. An `absolute` box placed against a containing block | ||
| * in the clamp's flow (a control's own positioned wrapper) stays in the flow, | ||
| * and that containing block's box decides. A popover or dialog stops | ||
| * ownership in `isOwnedBy`, and a portal renders outside the clamp. | ||
| */ |
There was a problem hiding this comment.
Non-blocking: this block describes flowBox, but containingBlock was inserted below it, so containingBlock now reads as "The box whose position decides whether el is cut off" and flowBox (line 196) has no comment. Moving the block back above flowBox fixes both.
cixzhang
left a comment
There was a problem hiding this comment.
(Posted by Cindy's agent on her behalf.) Engineering-owner approval at this exact head; it supersedes my 08/27 and 09/02 change requests. The evidence map in the PR body shows each point fixed here, and the Lab rule for what the clamp blocks is written in the docs. Thanks for the contribution!



Closes #4180
Text'smaxLinestruncates a single text node;LineClampis the composable version: wrap it around any children (mixed inline content, nested elements) to clamp the whole block to N lines.useTruncation(the same overflow-detection hookTextuses) rather than reinventing measurementTextandHeading, under the same name,hasTruncateTooltip@astryxdesign/labper the lab → core graduation path (no spec-protocol proposal needed for lab)Testing
npx vitest run packages/lab/src/LineClamp: 22 tests pass. The cases for a clipped<summary>andcontenteditable, and for a link restored and hidden again within one task, fail on the previous head and pass here.packages/core/src/utils/sharedMutationObserver.test.tscovers the records each registration now receives and the old-value option.tsc --noEmiton Core is clean, strict ESLint reports no errors on the changed files, andnode scripts/sync-exports.js --checkpasses. Lab's own typecheck here reads Core's built types, which are stale locally, so LineClamp was typechecked against the source of the newinternal/line-clampentry instead.Maintainer follow-up
(Posted by Cindy's agent on her behalf.) Carried on this branch with the author's commits kept. Exact head: 05a28c4.
main. The conflicts were insharedMutationObserver.ts, wheremainaddedflushMutationsand this branch passes each registration its records (both kept), and in the internal-entry lists inpackage.jsonandscripts/sync-exports.js(both entries kept).hasTruncateTooltip?: boolean(on/off, the same name and meaning as Text's) plustruncateTooltipPlacement?: LayerPlacement(default'above', Text's default placement). The tooltip props follow Text's: when Text'shasTruncateTooltipis renamed in a minor (public-component-api INV9), LineClamp follows.display: none) stays inert until the edge observer sees it on a visible line. Adisplay: contentscandidate is left to its children. Ahidden,classorstylechange runs the pass only on a candidate or an ancestor of one, so decorative animation inside the clamp reads no layout. Real Chrome 157 on this head's preview ("With Clipped Link",maxLines6, tooltip off):display: contentslink with the clamp scrolled above the viewport, and after scrolling back: it is never made inert.requestAnimationFrameopacity loop inside the clamp: 0 rect reads in 60 frames.hiddentoggle: 10 inert flips, and every reading matches the link's position.LineClamp.test.tsx"checks again when a link crosses the clip edge with no resize, mutation, render or font event" fails without it. In real Chrome 157 on this head's preview (story "With Clipped Link",maxLines6, widths 300–376 px), changing the clamp's letter spacing re-wraps the lines at the same 144 px box size, with no resize or watched attribute change. The trailing link crossed the edge 12 times, and after every change itsinertstate matched its position.inertis not lost before the clamp sees it. The clamp hands back queued mutation records before each sync and before it unsubscribes. A release defers every clamp's clipping pass until React's commit is done, so a commit lays the page out once.What LineClamp makes inert (Specs' Lab rule, in
LineClamp.doc.mjs)"LineClamp makes a focusable descendant inert only when both hold: (1) it is in the clamp's own flow. A positioned element is in that flow when its containing block is an element inside the clamp that is itself in the flow, as a control's own positioned wrapper is; the line test then applies to that containing block's box. A fixed element, an absolute element whose containing block is the clamp itself or lies outside it, a top-layer element (a popover or dialog), and anything rendered elsewhere through a portal each start a subtree that is never made inert, at any depth. (2) its box lies wholly beyond the clamp's last visible line. A control any part of which is visible stays reachable. A focusable with no box when LineClamp checks is treated as beyond the last line until it gains a box; LineClamp re-checks then. LineClamp re-checks when its size, its content or its fonts change. Gap: an absolutely placed control that the clamp itself clips stays a tab stop; the author owns positioned content inside a clamp."
Tests: a hidden CheckboxInput revealed past the edge by a change outside the clamp (stays inert), a hidden and a visible CheckboxInput and Switch (their native input is judged by its in-flow wrapper), a positioned subtree at any depth (a menu link, a submenu link, a
fixedcontrol), a Close button placed against an escaping panel, a partly visible link, a popover inside the clamp, plus the earlier cases.Tracked follow-up (outside the Lab rule, re-reviewed at graduation): a hidden
position: absolutecontrol inside a transformed, filtered, contained orwill-changewrapper can become a tab stop when it is later shown past the edge; and a doc comment needs to move back aboveflowBox.Earlier review points → evidence at 05a28c4
titleshowed the full text twice (as Text before #5559)title; the Tooltip alone carries the full textLineClamp.test.tsx"sets no native title on a truncated clamp: the Tooltip alone carries the full text" and "does not set a title/tooltip when content is not truncated"mergeRefsrecreated each render, re-calling the consumer ref and re-registering truncation measurementuseMergedRefs; a stable ref is called onceLineClamp.test.tsx"calls a caller's stable ref once across re-renders" (one call across two re-renders) and "forwards ref to the root element"maxLines2 the link is inert, and Tab goes clamp root → out of the clamp, withscrollTop0 and the first line unchanged. AtmaxLines7 the link wraps across the clip edge: Tab goes clamp root → link → out, withscrollTop0 and the first line unchanged. AtmaxLines8 the text fits, the clamp is no tab stop, and Tab reaches the link. Unit tests cover the clipping pass (the "tab order" suite)CI:
ci:run. No accessibility test or spec changed, soci:run-a11ydoes not apply.