描述列表
展示多个只读字段的组合。
何时使用
常见于详情页的信息展示。
// >= 5.8.0 可用,推荐的写法 ✅
const items: DescriptionsProps['items'] = [
{
key: '1',
label: 'UserName',
children: <p>Zhou Maomao</p>,
},
{
key: '2',
label: 'Telephone',
children: <p>1810000000</p>,
},
{
key: '3',
label: 'Live',
children: <p>Hangzhou, Zhejiang</p>,
},
{
key: '4',
label: 'Remark',
children: <p>empty</p>,
},
{
key: '5',
label: 'Address',
children: <p>No. 18, Wantang Road, Xihu District, Hangzhou, Zhejiang, China</p>,
},
];
<Descriptions title="User Info" items={items} />;
// <5.8.0 可用,>=5.8.0 时不推荐 🙅🏻♀️
<Descriptions title="User Info">
<Descriptions.Item label="UserName">Zhou Maomao</Descriptions.Item>
<Descriptions.Item label="Telephone">1810000000</Descriptions.Item>
<Descriptions.Item label="Live">Hangzhou, Zhejiang</Descriptions.Item>
<Descriptions.Item label="Remark">empty</Descriptions.Item>
<Descriptions.Item label="Address">
No. 18, Wantang Road, Xihu District, Hangzhou, Zhejiang, China
</Descriptions.Item>
</Descriptions>;
代码演示
-
基本 ·
basic -
带边框的 ·
border -
自定义尺寸 ·
size -
响应式 ·
responsive -
垂直 ·
vertical -
垂直带边框的 ·
vertical-border -
自定义语义结构的样式和类 ·
style-class -
整行 ·
block
API
通用属性参考:通用属性
Descriptions
| 参数 | 说明 | 类型 | 默认值 | 版本 | 全局配置 |
|---|---|---|---|---|---|
| bordered | 是否展示边框 | boolean | false | × | |
| classNames | 用于自定义组件内部各语义化结构的 class,支持对象或函数 | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 5.23.0 | |
| colon | 配置 Descriptions.Item 的 colon 的默认值。表示是否显示 label 后面的冒号 | boolean | true | × | |
| column | 一行的 DescriptionItems 数量,可以写成像素值或支持响应式的对象写法 { xs: 8, sm: 16, md: 24} | number | Record<Breakpoint, number> | 3 | × | |
自定义内容样式,请使用 styles.content 替换 | CSSProperties | - | 4.10.0 | × | |
| extra | 描述列表的操作区域,显示在右上方 | ReactNode | - | 4.5.0 | × |
| items | 描述列表项内容 | DescriptionsItem[] | - | 5.8.0 | × |
自定义标签样式,请使用 styles.label 替换 | CSSProperties | - | 4.10.0 | × | |
| layout | 描述布局 | horizontal | vertical | horizontal | × | |
| size | 设置列表的大小。可以设置为 medium 、small, 或不填 | large | medium | small | large | × | |
| styles | 用于自定义组件内部各语义化结构的行内 style,支持对象或函数 | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 5.23.0 | |
| title | 描述列表的标题,显示在最顶部 | ReactNode | - | × |
DescriptionItem
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
自定义内容样式,请使用 styles.content 替换 | CSSProperties | - | 4.9.0 | |
| label | 内容的描述 | ReactNode | - | |
自定义标签样式,请使用 styles.label 替换 | CSSProperties | - | 4.9.0 | |
| span | 包含列的数量(filled 铺满当前行剩余部分) | number| filled | Screens | 1 | screens: 5.9.0,filled: 5.22.0 |
span 是 Description.Item 的数量。 span={2} 会占用两个 DescriptionItem 的宽度。当同时配置
style和labelStyle(或contentStyle)时,两者会同时作用。样式冲突时,后者会覆盖前者。
Semantic DOM
| 语义节点 | 原生说明 | 版本 |
|---|---|---|
root | 根元素,包含描述列表容器的基础样式、重置样式、边框样式、布局方向等整体样式 | 5.23.0 |
header | 头部元素,包含flex布局、对齐方式、下边距等头部区域的布局和样式控制 | 5.23.0 |
title | 标题元素,包含文本省略、flex占比、颜色、字体权重、字体大小、行高等标题文字样式 | 5.23.0 |
extra | 额外内容元素,包含左边距、颜色、字体大小等额外操作区域的样式 | 5.23.0 |
label | 标签元素,包含颜色、字体权重、字体大小、行高、文本对齐、冒号样式等标签文字的样式 | 5.23.0 |
content | 内容元素,包含表格单元格布局、颜色、字体大小、行高、文字换行等内容展示样式 | 5.23.0 |
语义说明来源: vendor/components/descriptions/demo/_semantic.tsx
主题变量(Design Token)
类型、继承关系和原生令牌声明保持固定源码原文;默认值由原生主题计算,并可能受 ConfigProvider 覆盖。本表不伪造静态默认值。
| 令牌 | 类型 | 原生说明 |
|---|---|---|
labelBg | string | 标签背景色 |
labelColor | string | 标签文字颜色 |
titleColor | string | 标题文字颜色 |
titleMarginBottom | number | 标题下间距 |
itemPaddingBottom | number | 子项下间距 |
itemPaddingEnd | number | 子项结束间距 |
colonMarginRight | number | 冒号右间距 |
colonMarginLeft | number | 冒号左间距 |
contentColor | string | 内容区域文字颜色 |
extraColor | string | 额外区域文字颜色 |
声明来源: vendor/components/descriptions/style/index.ts
import { unit } from '@ant-design/cssinjs';
import type { CSSObject } from '@ant-design/cssinjs';
import { resetComponent, textEllipsis } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
// Component token here
/**
* @desc 标签背景色
* @descEN Background color of label
*/
labelBg: string;
/**
* @desc 标签文字颜色
* @descEN Text color of label
*/
labelColor: string;
/**
* @desc 标题文字颜色
* @descEN Text color of title
*/
titleColor: string;
/**
* @desc 标题下间距
* @descEN Bottom margin of title
*/
titleMarginBottom: number;
/**
* @desc 子项下间距
* @descEN Bottom padding of item
*/
itemPaddingBottom: number;
/**
* @desc 子项结束间距
* @descEN End padding of item
*/
itemPaddingEnd: number;
/**
* @desc 冒号右间距
* @descEN Right margin of colon
*/
colonMarginRight: number;
/**
* @desc 冒号左间距
* @descEN Left margin of colon
*/
colonMarginLeft: number;
/**
* @desc 内容区域文字颜色
* @descEN Text color of content
*/
contentColor: string;
/**
* @desc 额外区域文字颜色
* @descEN Text color of extra area
*/
extraColor: string;
}
interface DescriptionsToken extends FullToken<'Descriptions'> {}
原生通用属性
Tips: 以下通用属性适用于 antd 大部分组件,不支持的组件会单独说明。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| style | 自定义样式 | CSSProperties | - |
| className | 自定义类名 | string | - |
| rootClassName | 添加在组件最外层的 className | string | - |
| autoFocus | 自动获取焦点,仅对表单类、链接、交互容器等可聚焦元素生效 | boolean | false |
安装并复现示例
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
使用 ConfigProvider 和原生 App,并单独配置 dayjs 语言。每个示例在查看代码中列出完整源码文件和额外固定依赖。示例名称用于选择演示,不是组件通用属性。主题、语言与 SSR 初始化见资源安装指南。
原生类型参考
源码查看器包含未修改的原生实现和以下声明文件,继承类型仍位于原生包中。代码中的英文注释保留为源码参考。
vendor/components/descriptions/Cell.tsxvendor/components/descriptions/DescriptionsContext.tsvendor/components/descriptions/Item.tsvendor/components/descriptions/Row.tsxvendor/components/descriptions/index.tsxvendor/components/descriptions/style/index.ts
来源与许可
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
保留原生中英文正文与可执行示例;官网专用的嵌入章节和令牌表格在本地展开。Ant Design 使用 MIT 许可,另列依赖的许可证也需保留。上传预览禁止向外发起请求,不提供后端服务。