JGuang

描述列表

Descriptions · Ant Design

交互预览
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

描述列表

展示多个只读字段的组合。

何时使用

常见于详情页的信息展示。

// >= 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是否展示边框booleanfalse×
classNames用于自定义组件内部各语义化结构的 class,支持对象或函数Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.23.0
colon配置 Descriptions.Item 的 colon 的默认值。表示是否显示 label 后面的冒号booleantrue×
column一行的 DescriptionItems 数量,可以写成像素值或支持响应式的对象写法 { xs: 8, sm: 16, md: 24}number | Record<Breakpoint, number>3×
contentStyle自定义内容样式,请使用 styles.content 替换CSSProperties-4.10.0×
extra描述列表的操作区域,显示在右上方ReactNode-4.5.0×
items描述列表项内容DescriptionsItem[]-5.8.0×
labelStyle自定义标签样式,请使用 styles.label 替换CSSProperties-4.10.0×
layout描述布局horizontal | verticalhorizontal×
size设置列表的大小。可以设置为 medium 、small, 或不填large | medium | smalllarge×
styles用于自定义组件内部各语义化结构的行内 style,支持对象或函数Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.23.0
title描述列表的标题,显示在最顶部ReactNode-×

DescriptionItem

参数说明类型默认值版本
contentStyle自定义内容样式,请使用 styles.content 替换CSSProperties-4.9.0
label内容的描述ReactNode-
labelStyle自定义标签样式,请使用 styles.label 替换CSSProperties-4.9.0
span包含列的数量(filled 铺满当前行剩余部分)number| filled | Screens1screens: 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 覆盖。本表不伪造静态默认值。

令牌类型原生说明
labelBgstring标签背景色
labelColorstring标签文字颜色
titleColorstring标题文字颜色
titleMarginBottomnumber标题下间距
itemPaddingBottomnumber子项下间距
itemPaddingEndnumber子项结束间距
colonMarginRightnumber冒号右间距
colonMarginLeftnumber冒号左间距
contentColorstring内容区域文字颜色
extraColorstring额外区域文字颜色

声明来源: 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添加在组件最外层的 classNamestring-
autoFocus自动获取焦点,仅对表单类、链接、交互容器等可聚焦元素生效booleanfalse

安装并复现示例

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

使用 ConfigProvider 和原生 App,并单独配置 dayjs 语言。每个示例在查看代码中列出完整源码文件和额外固定依赖。示例名称用于选择演示,不是组件通用属性。主题、语言与 SSR 初始化见资源安装指南。

原生类型参考

源码查看器包含未修改的原生实现和以下声明文件,继承类型仍位于原生包中。代码中的英文注释保留为源码参考。

  • vendor/components/descriptions/Cell.tsx
  • vendor/components/descriptions/DescriptionsContext.ts
  • vendor/components/descriptions/Item.ts
  • vendor/components/descriptions/Row.tsx
  • vendor/components/descriptions/index.tsx
  • vendor/components/descriptions/style/index.ts

来源与许可

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

保留原生中英文正文与可执行示例;官网专用的嵌入章节和令牌表格在本地展开。Ant Design 使用 MIT 许可,另列依赖的许可证也需保留。上传预览禁止向外发起请求,不提供后端服务。