Skip to content

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

Open
HelloOjasMutreja wants to merge 1 commit into
facebook:mainfrom
HelloOjasMutreja:feat/lab-line-clamp
Open

feat(lab): add LineClamp — clamp arbitrary content to N lines#4259
HelloOjasMutreja wants to merge 1 commit into
facebook:mainfrom
HelloOjasMutreja:feat/lab-line-clamp

Conversation

@HelloOjasMutreja

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 pattern as Text's hasTruncateTooltip, via hasTooltip
  • Ships in @astryxdesign/lab per the lab → core graduation path (no spec-protocol proposal needed for lab)

Testing

  • 8 new colocated tests + full @astryxdesign/lab suite (256/256 pass)
  • tsc --noEmit clean
  • eslint clean
  • Manually verified in Storybook: clamping actually applies (-webkit-line-clamp in computed style, overflow correctly detected via scrollHeight/offsetHeight), tooltip shows full content only when truncated (no tooltip/title when content fits), mixed inline content (bold/italic/code) composes correctly inside the clamp

Opening as a draft per the contributing guide — will mark ready after final self-review.

@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 (UTC)
astryx Ready Ready Preview, Comment Jul 25, 2026 5:37am

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.

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

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

Closes facebook#4180
@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

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

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)

1 participant