Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

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

Cindy Zhanga6457889e4f5
diff --git a/packages/core/src/List/List.doc.mjs b/packages/core/src/List/List.doc.mjs
index 7d332e9742..e501667f28 100644
--- a/packages/core/src/List/List.doc.mjs
+++ b/packages/core/src/List/List.doc.mjs
@@ -146,8 +146,9 @@ export const docs = {
},
{
name: 'description',
- type: 'string',
- description: 'Secondary text displayed below the label.',
+ type: 'ReactNode',
+ description:
+ 'Secondary content below the label. A plain string gets single-line truncation automatically; a ReactNode lets child components control their own wrapping and line-clamp behavior.',
},
{
name: 'startContent',
@@ -340,8 +341,9 @@ export const docsZh = {
},
{
name: 'description',
- type: 'string',
- description: '显示在标签下方的次要文本。',
+ type: 'ReactNode',
+ description:
+ '标签下方的次要内容。纯字符串会自动应用单行截断;ReactNode 允许子组件自行控制换行和多行截断行为。',
},
{
name: 'startContent',
diff --git a/packages/core/src/List/XDSList.test.tsx b/packages/core/src/List/XDSList.test.tsx
index bf265d21fc..48efef59fc 100644
--- a/packages/core/src/List/XDSList.test.tsx
+++ b/packages/core/src/List/XDSList.test.tsx
@@ -571,4 +571,43 @@ describe('XDSList', () => {
expect(screen.getByText('Label Only')).toBeInTheDocument();
expect(screen.queryByText('undefined')).not.toBeInTheDocument();
});
+
+ // ===========================================================================
+ // ReactNode description
+ // ===========================================================================
+
+ it('accepts ReactNode as description', () => {
+ render(
+ <XDSList>
+ <XDSListItem
+ label="Item"
+ description={
+ <div>
+ <span>Rich</span> <span>description</span>
+ </div>
+ }
+ />
+ </XDSList>,
+ );
+ expect(screen.getByText('Rich')).toBeInTheDocument();
+ expect(screen.getByText('description')).toBeInTheDocument();
+ });
+
+ it('still accepts string description', () => {
+ render(
+ <XDSList>
+ <XDSListItem label="Item" description="Simple text" />
+ </XDSList>,
+ );
+ expect(screen.getByText('Simple text')).toBeInTheDocument();
+ });
+
+ it('accepts number as description (ReactNode)', () => {
+ render(
+ <XDSList>
+ <XDSListItem label="Count" description={42} />
+ </XDSList>,
+ );
+ expect(screen.getByText('42')).toBeInTheDocument();
+ });
});
diff --git a/packages/core/src/List/XDSListItem.tsx b/packages/core/src/List/XDSListItem.tsx
index 11e5e8de01..deb5a644b0 100644
--- a/packages/core/src/List/XDSListItem.tsx
+++ b/packages/core/src/List/XDSListItem.tsx
@@ -41,9 +41,13 @@ export interface XDSListItemProps {
label: string;
/**
- * Secondary description text below the label.
+ * Secondary description below the label.
+ *
+ * Accepts a plain string (single-line truncation applied automatically)
+ * or a ReactNode for rich/multi-line content (no wrapping constraints
+ * applied — child components control their own text behavior).
*/
- description?: string;
+ description?: ReactNode;
/**
* Content rendered before the item (icon, avatar, checkbox).
@@ -225,6 +229,9 @@ const styles = stylex.create({
description: {
color: colorVars['--color-text-secondary'],
overflow: 'hidden',
+ minWidth: 0,
+ },
+ descriptionString: {
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
@@ -315,12 +322,18 @@ export function XDSListItem({
const hasMarkers = ctx?.hasMarkers ?? false;
const isInteractive = onClick != null || href != null;
+ const isStringDescription = typeof description === 'string';
+
const labelAndDescription = (
<>
<span {...stylex.props(styles.label)}>{label}</span>
{description != null && (
<span
- {...stylex.props(styles.description, descriptionSizeStyles[density])}>
+ {...stylex.props(
+ styles.description,
+ isStringDescription && styles.descriptionString,
+ descriptionSizeStyles[density],
+ )}>
{description}
</span>
)}