Skip to content

feat(lab): add LineClamp — clamp arbitrary content to N lines - #4259

Merged
cixzhang merged 39 commits into
meta:mainfrom
HelloOjasMutreja:feat/lab-line-clamp
Nov 8, 2026
Merged

cixzhang merged 39 commits into
meta:mainfrom
HelloOjasMutreja:feat/lab-line-clamp

Conversation

@HelloOjasMutreja

@HelloOjasMutreja HelloOjasMutreja commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4180

Text's maxLines truncates a single text node; LineClamp is the composable version: wrap it around any children (mixed inline content, nested elements) to clamp the whole block to N lines.

  • Reuses useTruncation (the same overflow-detection hook Text uses) rather than reinventing measurement
  • Same optional-tooltip-on-truncation switch as Text and Heading, under the same name, hasTruncateTooltip
  • Ships in @astryxdesign/lab per 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> and contenteditable, 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.ts covers the records each registration now receives and the old-value option.
  • tsc --noEmit on Core is clean, strict ESLint reports no errors on the changed files, and node scripts/sync-exports.js --check passes. Lab's own typecheck here reads Core's built types, which are stale locally, so LineClamp was typechecked against the source of the new internal/line-clamp entry instead.
  • Storybook was last checked in an earlier round (clamping applies, and the tooltip shows only when truncated); it was not re-run at this head.

Maintainer follow-up

(Posted by Cindy's agent on her behalf.) Carried on this branch with the author's commits kept. Exact head: 05a28c4.

  • Merged main. The conflicts were in sharedMutationObserver.ts, where main added flushMutations and this branch passes each registration its records (both kept), and in the internal-entry lists in package.json and scripts/sync-exports.js (both entries kept).
  • Tooltip contract: hasTruncateTooltip?: boolean (on/off, the same name and meaning as Text's) plus truncateTooltipPlacement?: LayerPlacement (default 'above', Text's default placement). The tooltip props follow Text's: when Text's hasTruncateTooltip is renamed in a minor (public-component-api INV9), LineClamp follows.
  • The tooltip is Core's shared truncation tooltip, the one Text and Heading use. It mounts on the first hover, completed tap or focus, so a page of clamped content mounts no tooltip layers at load. Its content uses the shared truncation tooltip style. A truncated clamp's tab stop shows the shared keyboard focus outline.
  • The clipping pass runs on each render, on a resize, on a child mutation, on blur, and whenever a managed focusable crosses the clip edge: an IntersectionObserver rooted at the clamp covers lines that re-wrap at the same box size, such as a late web font or an ancestor's font change. Its thresholds are 0 and just above 0, so a link that lands exactly on the edge (ratio 0, yet clipped) is reported too. The pass decides from geometry, over the focusables the clamp owns: a nested clamp, a popover or a dialog (both render in the top layer, which the clamp does not clip) manages its own. A candidate with no box at all (display: none) stays inert until the edge observer sees it on a visible line. 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 decorative animation inside the clamp reads no layout. Real Chrome 157 on this head's preview ("With Clipped Link", maxLines 6, tooltip off):
    • A class on an ancestor outside the clamp hides the link, then shows it past the edge: the link stays inert, and Tab never reaches it.
    • A display: contents link with the clamp scrolled above the viewport, and after scrolling back: it is never made inert.
    • A decorative requestAnimationFrame opacity loop inside the clamp: 0 rect reads in 60 frames.
    • Same-size re-wraps (letter spacing at 340, 360 and 376 px) plus a hidden toggle: 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", maxLines 6, 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 its inert state matched its position.
  • A caller's inert is 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 fixed control), 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: absolute control inside a transformed, filtered, contained or will-change wrapper can become a tab stop when it is later shown past the edge; and a doc comment needs to move back above flowBox.

Earlier review points → evidence at 05a28c4

Review point Outcome Evidence
08/27 (a): the Tooltip and a native title showed the full text twice (as Text before #5559) No native title; the Tooltip alone carries the full text LineClamp.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"
08/27 (b): mergeRefs recreated each render, re-calling the consumer ref and re-registering truncation measurement useMergedRefs; a stable ref is called once LineClamp.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"
09/02 (c): a fully clipped link was the next Tab stop, and focusing it scrolled the clamp 72px and swapped the visible line A fully clipped focusable is inert, so it is not a Tab stop. Focus never scrolls the clamp. A partly visible focusable stays a Tab stop without a scroll Real Chrome 157 on this head's preview, story "With Clipped Link". At maxLines 2 the link is inert, and Tab goes clamp root → out of the clamp, with scrollTop 0 and the first line unchanged. At maxLines 7 the link wraps across the clip edge: Tab goes clamp root → link → out, with scrollTop 0 and the first line unchanged. At maxLines 8 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, so ci:run-a11y does not apply.

@vercel

vercel Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 8, 2026 9:55am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 23, 2026
@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 Jul 23, 2026
@HelloOjasMutreja
HelloOjasMutreja marked this pull request as ready for review July 24, 2026 05:22
@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Visual before/after, verified against the live Storybook story:

LineClamp before and after

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.

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

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.

@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 05a28c4

Storybook · Sandbox · built from this PR's head

Modified components

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

@cixzhang

Copy link
Copy Markdown
Contributor

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.mov

We'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.

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

@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.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@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.

github-actions Bot added a commit that referenced this pull request Aug 11, 2026
github-actions Bot added a commit that referenced this pull request Aug 27, 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 — 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
Current Text control LineClamp hovered

[Reviewed by Robohands]

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Pushed 4a5eba7 with both patterns carried over from #5559:

  • Dropped the native title={tooltipEnabled ? truncation.fullText : undefined} entirely, matching Text's current shape — no more double announcement between the native title tooltip and the Tooltip component.
  • Replaced mergeRefs(ref, truncation.ref, elementRef) (called inline, so a new callback every render) with useMergedRefs(ref, truncation.ref, elementRef), matching Text's mergedRef.

Verified against Text.tsx's current render block (lines 272-284) line by line to make sure the shape actually matches rather than approximating it.

@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.

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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 3cf7835

@astracat-bot astracat-bot Bot 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.

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 a display: contents wrapper with a tabindex, is now marked inert for good by the 0×0 test at LineClamp.tsx:134, so keyboard and screen reader users cannot reach it; testing el.getClientRects().length === 0 for "no box", skipping display: contents candidates 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 1be18ac

@astracat-bot astracat-bot Bot 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.

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: contents after LineClamp marked it inert (for example a link shown by removing a display: none class, or a tabindex wrapper that turns display: contents as the box widens) keeps inert on a visible line, because the new skip at LineClamp.tsx:132 runs 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 from display: none to display: contents on 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 4efa57d

@astracat-bot astracat-bot Bot 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.

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 a display: none candidate reads as top 0 and the pass now relies on hidden, class and style changes 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 rects inert until the edge observer reports it on a visible line, as the previous commit did, would fix it.
  • Miss: a display: contents link on a visible line is made inert by 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 a display: contents candidate 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 getBoundingClientRect reads in one second for a decorative span animated by requestAnimationFrame), because class and style records 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 89a6212

@astracat-bot astracat-bot Bot 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.

Changes requested: one defect remains in LineClamp's clipping pass.

  • Miss: a Popover placed inside a clamp renders inside it (Core keeps layers inline under a div) in the top layer, which overflow: clip does not clip, yet the clipping pass (LineClamp.tsx:144-147) makes every popover control at or below the clamp's bottom edge inert, so Duplicate and Delete ignore clicks and Tab; stopping ownership at a layer boundary in isOwnedBy (for example closest('[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]

cixzhang and others added 2 commits November 7, 2026 23:49
… 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 7d6cdc5

@astracat-bot astracat-bot Bot 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.

Changes requested: one defect remains in LineClamp's clipping pass.

  • Miss: a control the clamp does not clip is made inert when it is positioned out of flow below the clamp: in Chromium, a disclosure menu whose panel is position: absolute opens below a two-line clamp, and its Share and Report links ignore clicks and Tab (LineClamp.tsx:149-152); skipping candidates that sit inside an absolute or fixed element 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 0311acc

@astracat-bot astracat-bot Bot 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.

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: escapesClip stops at the innermost absolute box (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's offsetParent is 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 93d98c3

@astracat-bot astracat-bot Bot 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.

Changes requested: one defect remains in LineClamp's clipping pass.

  • Core's CheckboxInput and Switch stay keyboard-focusable while the clamp hides them: isInPositionedSubtree (LineClamp.tsx:171-183) never makes a position: absolute focusable 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 a fixed box, or an absolute box whose offsetParent is 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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec a98b661

@astracat-bot astracat-bot Bot 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.

Changes requested: one defect remains in LineClamp's clipping pass.

  • A Core CheckboxInput or Switch that is hidden (display: none) when the clamp checks is released, because flowBox (LineClamp.tsx:187-189) reads its null offsetParent as 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 it inert, and a test with a hidden CheckboxInput that 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]

Comment on lines +170 to +172
* 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

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.

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]>
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 05a28c4

@astracat-bot astracat-bot Bot 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.

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: absolute control inside a transformed (or filter, 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 at position; 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 new containingBlock (LineClamp.tsx:166-174); moving it back above flowBox keeps each function described.

[Automated review]

ancestor != null;
ancestor = ancestor.parentElement
) {
if (getComputedStyle(ancestor).position !== 'static') {

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.

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.

Comment on lines +166 to +174
/**
* 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.
*/

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.

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 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.

(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!

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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.

feat(lab): LineClamp — clamp arbitrary content to N lines (port from XDSLineClamp)

2 participants