Repository navigation
docs(useTruncation): add hook docs and a live table cell truncation example block - #10555
Conversation
…xample block Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks for filling the useTruncation docs gap. The hook doc matches the hook's source, and in a browser the example opens the full-path tooltip only on the two cut-off cells. Two things need fixing before this can go in:
<Table width={380}>inuseTruncationHookUsage.tsx(line 87) fails the type check with TS2322 becauseTablehas nowidthprop, which breaks the CLI typecheck and the docs build, so drop the prop, since each span'smaxWidth: 120already forces the cut.- The test "gates tooltips so that truncated cells enable tooltips and fitting cells do not" only asserts that three spans render and still passes with
isEnabledhard-coded totrueorfalse, so either hover each cell and assert that only the two long paths open a tooltip with their full text, or rename the test and drop the gating claim from the description.
Optional: the path spans are not focusable, so keyboard users cannot open the full path (Text has the same known gap), and tabIndex={truncation.isTruncated ? 0 : undefined} on the span would close it in the example.
[Automated review]
Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
|
Addressed review feedback:
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Text · Storybook | 13.4 kB (0) · 5.4 kB CSS (0) | 717 (0) | ✓ · ✓ · — |
Package size:
- @astryxdesign/cli 3.57 MB packed (+834 B); no new dependencies
- @astryxdesign/core 7.28 MB packed (+1.3 kB); no new dependencies
API changes: none in this pull request
Committed API report behind this build: cli 36 rows, core 36 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
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, so a maintainer needs to add the ci:run label for it to run.
Thanks for the quick follow-up. The example now type-checks, and in a browser the full-path tooltip opens by hover and by Tab only on the two cut-off paths, while README.md stays out of the tab order.
Optional, non-blocking:
- The description still says the tests verify "conditional Tooltip gating"; they only render the block, so that phrase can go.
useTruncation.doc.mjssays to render the Tooltip only whenisTruncatedis true, while the example keeps it mounted and gates it withisEnabled; matching the wording to the example (or the example to the wording) keeps the guidance consistent.- Without the old
width, the table fills its container and the paths clip at the span's 120 px with room left in the column; constraining the column instead would make the cut look like a real one.
[Automated review]
There was a problem hiding this comment.
Thanks for adding the useTruncation docs page and example block; the example behaves as described, but one fix is needed before this can merge.
- Found by CI: the required
lintcheck fails because no Changeset names@astryxdesign/core(foruseTruncation.doc.mjs) or@astryxdesign/cli(for the new example block), so add one, for example withpnpm changeset:new --packages @astryxdesign/core,@astryxdesign/cli --category docs.
Optional: the hook doc says to render the Tooltip only when isTruncated is true while the example keeps it mounted and gates it with isEnabled, and the description still says the tests verify Tooltip gating, so aligning that wording would help readers.
[Automated review]
| { | ||
| guidance: true, | ||
| description: | ||
| 'Render the full-content Tooltip only when isTruncated is true, and read the tooltip text from fullText: a cell that fits shows no tooltip, and the text always matches what was measured.', |
There was a problem hiding this comment.
Non-blocking: the example block keeps every Tooltip mounted and gates it with isEnabled, so it does not do what this line says, and the fitting README.md span still gets aria-describedby to a hidden tooltip. Either say "enable the Tooltip only when isTruncated is true" here (and on line 46 and in the usage text), or mount the Tooltip conditionally in the block.
…design/cli Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
|
Added the requested |
There was a problem hiding this comment.
Thanks for adding the Changeset: that was the last blocking item, and the useTruncation docs page and example block are approved. The required checks pass on this head.
Optional, non-blocking:
- Regression:
useTruncation.doc.mjssays the first measurement "runs batched in a microtask after the commit", but since #10668 onmaina new element is first measured in the shared ResizeObserver's first notification, so that sentence and its twodocsDenseechoes are now out of date (suggested wording inline). - The doc says to render the Tooltip only when
isTruncatedis true, while the example keeps it mounted and gates it withisEnabled; aligning the wording or the example keeps the guidance consistent.
[Automated review]
| ], | ||
| usage: { | ||
| description: | ||
| "Detects whether an element's text is cut off — single-line overflow or clamped to several lines — and gives back the full text, updating when the size or the content changes. Built on a shared ResizeObserver and a shared MutationObserver, so hundreds of table cells create one observer of each kind, and a first measurement runs batched in a microtask after the commit instead of forcing a layout pass per text during mount. Use it wherever a truncated cell should show its full content only when it is actually truncated: compose a Tooltip off isTruncated and fullText instead of always rendering one. Text and Heading build their truncation tooltips on it; reach for it directly when composing truncation feedback into your own component.", |
There was a problem hiding this comment.
Non-blocking: since #10668 landed on main, a new element's first measurement comes from the shared ResizeObserver's first notification after layout, and the microtask runs only for an element another subscriber already observes, so "a first measurement runs batched in a microtask after the commit" no longer matches the hook. Suggested: "a new element is first measured in the shared ResizeObserver's first notification, after the browser's layout, so mounting many texts forces no extra layout pass." The docsDense text at lines 89 and 104 says the same.
|
Hi @cixzhang 👋 The changeset for |
|
/approve-spec 89967ab |
There was a problem hiding this comment.
Approved. Thanks for adding the useTruncation docs page and example block: the example opens the full path only on the cut-off cells, by hover and by Tab, and every required check passes on this head.
Optional, non-blocking:
useTruncation.doc.mjssays the first measurement "runs batched in a microtask after the commit" (line 57, repeated indocsDenseat lines 89 and 104), but the hook now measures a new element in the shared ResizeObserver's first notification and uses the microtask only for an element that something else already observes.- The doc says to render the Tooltip only when
isTruncatedis true (lines 46, 57, 62 and 108), while the example keeps it mounted and gates it withisEnabled; aligning the wording or the example keeps the guidance consistent. - The description still says the new tests verify conditional Tooltip gating; they only check that the rows and the three path spans render.
[Automated review]
|
/approve-spec 37509f9 |
There was a problem hiding this comment.
Approved. Thanks for filling the useTruncation docs gap. The hook page and the example block do what the description says: the cut-off paths open their full path on hover or Tab, and README.md opens nothing.
Non-blocking, if you touch the doc again:
useTruncation.doc.mjs:57(and the dense text at:89and:104) says the first measurement runs in a microtask after the commit; the hook now measures a new element in the shared ResizeObserver's first notification, after layout.:46and:62say to render the Tooltip only whenisTruncatedis true, while the example keeps it mounted and togglesisEnabled; aligning the wording or the block avoids mixed guidance.
[Automated review]
Resolves #9561
Reader impact
useTruncationhad no HookDoc and no docsite page, meaningastryx hook useTruncationfound nothing. With this PR, the hook has full documentation detailing its options (maxLines), return values (ref,isTruncated,fullText), shared observer architecture, and an interactive example block.The example block demonstrates a narrow table column with long file paths:
maxLines: 1) truncates with ellipsis and enables the Tooltip with the full text.maxLines: 2) clamps to 2 lines and enables the Tooltip.README.md) fits within the column width without truncation, keeping its Tooltip cleanly disabled.Source of truth
packages/core/src/Text/useTruncation.tsarchitecture:knowledge-contractsINV28Correction
packages/core/src/Text/useTruncation.doc.mjs(docs+docsDense,group: 'Text',importPath: '@astryxdesign/core/Text').blocks/components/Text/useTruncationHookUsage(exampleFor: 'useTruncation') demonstrating single-line and multi-line text truncation and gated Tooltip triggers.packages/cli/api/component/__fixtures__/resolutions/modules.txtsouseTruncationresolves toText/useTruncation.doc.mjs.internal/shadcn-registry/routes.lock.jsonandapps/sandbox/scripts/next-export-routes.json.packages/cli/api/template/use-truncation-hook-usage.test.tsxverifying DOM rendering and conditional Tooltip gating.Evidence
packages/cli/api/template/use-truncation-hook-usage.test.tsx(2/2 passing).apps/sandbox/src/route-manifest.test.ts(6/6 passing).pnpm check:knowledgepassed cleanly.astryx hook useTruncationrenders complete hook documentation.Scope
[✓] This PR changes documentation only, or names every necessary generated artifact.
[✓] Runtime, API, visual, and policy changes were removed or split.
[✓] Public text and artifacts contain no internal Meta content.