Back to Ant Design

Mentions

components/mentions/index.zh-CN.md

6.3.74.3 KB
Original Source

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

用于在输入中提及某人或某事,常用于发布、聊天或评论功能。

代码演示 {#examples}

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">基本使用</code> <code src="./demo/size.tsx" version="6.0.0">尺寸</code> <code src="./demo/variant.tsx">形态变体</code> <code src="./demo/async.tsx">异步加载</code> <code src="./demo/form.tsx">配合 Form 使用</code> <code src="./demo/prefix.tsx">自定义触发字符</code> <code src="./demo/readonly.tsx">无效或只读</code> <code src="./demo/placement.tsx">向上展开</code> <code src="./demo/allowClear.tsx">带移除图标</code> <code src="./demo/autoSize.tsx">自动大小</code> <code src="./demo/autosize-textarea-debug.tsx" debug>debug 自动大小</code> <code src="./demo/status.tsx">自定义状态</code> <code src="./demo/style-class.tsx" version="6.0.0">自定义语义结构的样式和类</code> <code src="./demo/render-panel.tsx" debug>_InternalPanelDoNotUseOrYouWillBeFired</code> <code src="./demo/component-token.tsx" debug>组件 Token</code>

API

通用属性参考:通用属性

Mentions

参数说明类型默认值版本
allowClear可以点击清除图标删除内容boolean | { clearIcon?: ReactNode }false5.13.0
autoSize自适应内容高度,可设置为 true | false 或对象:{ minRows: 2, maxRows: 6 }boolean | objectfalse
classNames用于自定义组件内部各语义化结构的 class,支持对象或函数Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
defaultValue默认值string-
filterOption自定义过滤逻辑false | (input: string, option: OptionProps) => boolean-
getPopupContainer指定建议框挂载的 HTML 节点() => HTMLElement-
notFoundContent当下拉列表为空时显示的内容ReactNodeNot Found
placement弹出层展示位置top | bottombottom
prefix设置触发关键字string | string[]@
split设置选中项前后分隔符string
size控件大小large | medium | small-
status设置校验状态'error' | 'warning'-4.19.0
validateSearch自定义触发验证逻辑(text: string, props: MentionsProps) => void-
value设置值string-
variant形态变体outlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.0
onBlur失去焦点时触发() => void-
onChange值改变时触发(text: string) => void-
onClear按下清除按钮的回调() => void-5.20.0
onFocus获得焦点时触发() => void-
onResizeresize 回调function({ width, height })-
onSearch搜索时触发(text: string, prefix: string) => void-
onSelect选择选项时触发(option: OptionProps, prefix: string) => void-
onPopupScroll滚动时触发(event: Event) => void-5.23.0
options选项配置Options[]5.1.0
styles用于自定义组件内部各语义化结构的行内 style,支持对象或函数Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-

Mentions 方法

名称描述
blur()移除焦点
focus()获取焦点

Option

参数说明类型默认值
value选择时填充的值string-
label选项的标题React.ReactNode-
key选项的 key 值string-
disabled是否可选boolean-
classNamecss 类名string-
style选项样式React.CSSProperties-

Semantic DOM

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

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

<ComponentTokenTable component="Mentions"></ComponentTokenTable>