Back to Ant Design

Tag

components/tag/index.zh-CN.md

6.3.74.0 KB
Original Source

何时使用 {#when-to-use}

  • 用于标记事物的属性和维度。
  • 进行分类。

代码演示 {#examples}

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">基本</code> <code src="./demo/colorful.tsx">多彩标签</code> <code src="./demo/control.tsx">动态添加和删除</code> <code src="./demo/checkable.tsx">可选择标签</code> <code src="./demo/animation.tsx">添加动画</code> <code src="./demo/icon.tsx">图标按钮</code> <code src="./demo/status.tsx">预设状态的标签</code> <code src="./demo/customize.tsx" debug>自定义关闭按钮</code> <code src="./demo/draggable.tsx">可拖拽标签</code> <code src="./demo/component-token.tsx" debug>组件 Token</code> <code src="./demo/disabled.tsx" debug>禁用标签</code> <code src="./demo/style-class.tsx" version="6.0.0">自定义语义结构的样式和类</code>

API

通用属性参考:通用属性

Tag

参数说明类型默认值版本
classNames用于自定义组件内部各语义化结构的 class,支持对象或函数Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
closeIcon自定义关闭按钮。5.7.0:设置为 nullfalse 时隐藏关闭按钮ReactNodefalse4.4.0
color标签色string-
disabled是否禁用标签booleanfalse6.0.0
href点击跳转的地址,指定此属性tag组件会渲染成 <a> 标签string-6.0.0
icon设置图标ReactNode-
onClose关闭时的回调(可通过 e.preventDefault() 来阻止默认行为)(e: React.MouseEvent<HTMLElement, MouseEvent>) => void-
styles用于自定义组件内部各语义化结构的行内 style,支持对象或函数Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
target相当于 a 标签的 target 属性,href 存在时生效string-6.0.0
variant标签变体'filled' | 'solid' | 'outlined''filled'6.0.0
bordered是否带边框,请使用 variant="filled" 替代booleantrue-

Tag.CheckableTag

参数说明类型默认值版本
checked设置标签的选中状态booleanfalse
icon设置图标ReactNode-5.27.0
onChange点击标签时触发的回调(checked) => void-

Tag.CheckableTagGroup

参数说明类型默认值版本
classNames用于自定义组件内部各语义化结构的 class,支持对象或函数Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-
defaultValue初始选中值string | number | Array<string | number> | null-
disabled禁用选中boolean-
multiple多选模式boolean-
options选项列表Array<{ label: ReactNode; value: string | number } | string | number>-
styles用于自定义组件内部各语义化结构的行内 style,支持对象或函数Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-
value选中值string | number | Array<string | number> | null-
onChange点击标签时触发的回调(value: string | number | Array<string | number> | null) => void-

Semantic DOM

Tag

<code src="./demo/_semantic.tsx" simplify="true"></code>

Tag.CheckableTagGroup {#semantic-group}

<code src="./demo/_semantic_group.tsx" simplify="true"></code>

主题变量(Design Token){#design-token}

<ComponentTokenTable component="Tag"></ComponentTokenTable>