Skip to content

fix(ListItem): support ReactNode for description prop, fix whiteSpace nowrap breaking line-clamp - #896

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/890-listitem-description-reactnode
Mar 26, 2026
Merged

fix(ListItem): support ReactNode for description prop, fix whiteSpace nowrap breaking line-clamp#896
cixzhang merged 1 commit into
mainfrom
navi/fix/890-listitem-description-reactnode

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #890 — two related issues with XDSListItem:

1. description prop now accepts ReactNode

Changed from string to ReactNode so consumers can pass rich content (multiple text elements, conditional rendering, inline truncation):

<XDSListItem
  label={item.title}
  description={
    <div>
      {item.snippet != null && (
        <XDSText type="supporting" maxLines={2}>{item.snippet}</XDSText>
      )}
      {item.creationTime != null && (
        <XDSText type="supporting">
          {formatRelativeTime(item.creationTime)}
        </XDSText>
      )}
    </div>
  }
/>

Backward compatible — plain strings still work exactly as before (single-line truncation applied automatically).

2. Fix whiteSpace: 'nowrap' breaking -webkit-line-clamp

The description wrapper previously applied whiteSpace: 'nowrap' unconditionally. This silently broke any child component using -webkit-line-clamp (e.g. maxLines on XDSText) because line-clamp requires text to be allowed to wrap.

Fix: Split into two style objects — descriptionString (with whiteSpace: nowrap + textOverflow: ellipsis) applied only when description is a plain string; the base description style has no wrapping constraints for ReactNode.

Changes

  • packages/core/src/List/XDSListItem.tsx — type change, split description styles, conditional style application
  • packages/core/src/List/List.doc.mjs — updated description prop type in docs
  • packages/core/src/List/XDSList.test.tsx — 3 new tests for ReactNode description variants

@cixzhang
cixzhang requested a review from josephfarina as a code owner March 26, 2026 01:14
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 26, 2026
@github-actions

github-actions Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

List · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 292B N/A
Lines of Code N/A 400 -
Complexity N/A Very High (36) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 11.1KB 17.6KB 2.7KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 critical.

XDSList - 1 issue(s)
  • 🔴 critical: Ensure an element's role supports its ARIA attributes
    • Rule: aria-allowed-attr · Affects 1/10 stories · Learn more
    • WCAG: 4.1.2 (Level A)

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

… nowrap breaking line-clamp

- Change `description` prop type from `string` to `ReactNode`
- Split description styles: string descriptions keep single-line truncation
  (whiteSpace: nowrap + textOverflow: ellipsis), ReactNode descriptions get
  no wrapping constraints so children can manage their own text behavior
- Update List.doc.mjs to reflect ReactNode type for description prop
- Add tests for ReactNode description variants

Fixes #890

Co-authored-by: Navi <navi@navibot.dev>
@cixzhang
cixzhang force-pushed the navi/fix/890-listitem-description-reactnode branch from 2edb729 to bfeaf31 Compare March 26, 2026 01:21
@cixzhang
cixzhang merged commit c7bd1fb into main Mar 26, 2026
14 checks passed
@cixzhang
cixzhang deleted the navi/fix/890-listitem-description-reactnode branch April 9, 2026 14:32
cixzhang added a commit that referenced this pull request Apr 26, 2026
… nowrap breaking line-clamp (#896)

- Change `description` prop type from `string` to `ReactNode`
- Split description styles: string descriptions keep single-line truncation
  (whiteSpace: nowrap + textOverflow: ellipsis), ReactNode descriptions get
  no wrapping constraints so children can manage their own text behavior
- Update List.doc.mjs to reflect ReactNode type for description prop
- Add tests for ReactNode description variants

Fixes #890

Co-authored-by: Navi <navi@users.noreply.github.com>
cixzhang added a commit that referenced this pull request Jun 21, 2026
… nowrap breaking line-clamp (#896)

- Change `description` prop type from `string` to `ReactNode`
- Split description styles: string descriptions keep single-line truncation
  (whiteSpace: nowrap + textOverflow: ellipsis), ReactNode descriptions get
  no wrapping constraints so children can manage their own text behavior
- Update List.doc.mjs to reflect ReactNode type for description prop
- Add tests for ReactNode description variants

Fixes #890

Co-authored-by: Navi <navi@users.noreply.github.com>
cixzhang added a commit that referenced this pull request Jun 21, 2026
… nowrap breaking line-clamp (#896)

- Change `description` prop type from `string` to `ReactNode`
- Split description styles: string descriptions keep single-line truncation
  (whiteSpace: nowrap + textOverflow: ellipsis), ReactNode descriptions get
  no wrapping constraints so children can manage their own text behavior
- Update List.doc.mjs to reflect ReactNode type for description prop
- Add tests for ReactNode description variants

Fixes #890
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XDSListItem: Support ReactNode for description prop and fix whiteSpace: nowrap blocking line-clamping

1 participant