2019-05-17 12:05:03 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
subtitle: 提及
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: 数据录入
|
2019-05-17 12:05:03 +08:00
|
|
|
|
title: Mentions
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*e4bXT7Uhi9YAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*pxR2S53P_xoAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
2019-05-17 12:05:03 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
提及组件。
|
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
|
|
用于在输入中提及某人或某事,常用于发布、聊天或评论功能。
|
|
|
|
|
|
2022-11-21 21:34:23 +08:00
|
|
|
|
### 5.1.0 用法升级
|
|
|
|
|
|
2023-02-05 19:03:59 +08:00
|
|
|
|
<Alert message="在 5.1.0 版本后,我们提供了 <Mentions options={[...]} /> 的简写方式,有更好的性能和更方便的数据组织方式,开发者不再需要自行拼接 JSX。同时我们废弃了原先的写法,你还是可以在 5.x 继续使用,但会在控制台看到警告,并会在 6.0 后移除。"></Alert>
|
2019-05-17 12:05:03 +08:00
|
|
|
|
|
|
|
|
|
```jsx
|
2022-11-21 21:34:23 +08:00
|
|
|
|
// >=5.1.0 可用,推荐的写法 ✅
|
|
|
|
|
const options = [{ value: 'sample', label: 'sample' }];
|
|
|
|
|
return <Mentions options={options} />;
|
|
|
|
|
|
|
|
|
|
// <5.1.0 可用,>=5.1.0 时不推荐 🙅🏻♀️
|
2023-02-05 19:03:59 +08:00
|
|
|
|
return (
|
|
|
|
|
<Mentions onChange={onChange}>
|
|
|
|
|
<Mentions.Option value="sample">Sample</Mentions.Option>
|
|
|
|
|
</Mentions>
|
|
|
|
|
);
|
2019-05-17 12:05:03 +08:00
|
|
|
|
```
|
|
|
|
|
|
2023-02-04 21:26:12 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
|
|
|
|
<!-- prettier-ignore -->
|
|
|
|
|
<code src="./demo/basic.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/autoSize.tsx">自动大小</code>
|
|
|
|
|
<code src="./demo/status.tsx">自定义状态</code>
|
|
|
|
|
<code src="./demo/render-panel.tsx" debug>_InternalPanelDoNotUseOrYouWillBeFired</code>
|
2023-05-31 10:37:40 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>组件 Token</code>
|
2023-02-04 21:26:12 +08:00
|
|
|
|
|
2022-11-21 21:34:23 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2019-09-02 15:25:11 +08:00
|
|
|
|
### Mentions
|
2019-05-17 12:05:03 +08:00
|
|
|
|
|
2022-02-16 21:14:05 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| autoFocus | 自动获得焦点 | boolean | false | |
|
|
|
|
|
| autoSize | 自适应内容高度,可设置为 true \| false 或对象:{ minRows: 2, maxRows: 6 } | boolean \| object | false | |
|
|
|
|
|
| defaultValue | 默认值 | string | - | |
|
|
|
|
|
| filterOption | 自定义过滤逻辑 | false \| (input: string, option: OptionProps) => boolean | - | |
|
|
|
|
|
| getPopupContainer | 指定建议框挂载的 HTML 节点 | () => HTMLElement | - | |
|
|
|
|
|
| notFoundContent | 当下拉列表为空时显示的内容 | ReactNode | `Not Found` | |
|
|
|
|
|
| placement | 弹出层展示位置 | `top` \| `bottom` | `bottom` | |
|
|
|
|
|
| prefix | 设置触发关键字 | string \| string\[] | `@` | |
|
|
|
|
|
| split | 设置选中项前后分隔符 | string | ` ` | |
|
|
|
|
|
| status | 设置校验状态 | 'error' \| 'warning' | - | 4.19.0 |
|
|
|
|
|
| validateSearch | 自定义触发验证逻辑 | (text: string, props: MentionsProps) => void | - | |
|
|
|
|
|
| value | 设置值 | string | - | |
|
|
|
|
|
| onBlur | 失去焦点时触发 | () => void | - | |
|
|
|
|
|
| onChange | 值改变时触发 | (text: string) => void | - | |
|
|
|
|
|
| onFocus | 获得焦点时触发 | () => void | - | |
|
|
|
|
|
| onResize | resize 回调 | function({ width, height }) | - | |
|
|
|
|
|
| onSearch | 搜索时触发 | (text: string, prefix: string) => void | - | |
|
|
|
|
|
| onSelect | 选择选项时触发 | (option: OptionProps, prefix: string) => void | - | |
|
2022-12-22 14:12:26 +08:00
|
|
|
|
| options | 选项配置 | [Options](#option) | [] | 5.1.0 |
|
2019-05-17 12:05:03 +08:00
|
|
|
|
|
2019-09-02 15:25:11 +08:00
|
|
|
|
### Mentions 方法
|
2019-05-17 12:05:03 +08:00
|
|
|
|
|
2022-02-16 21:14:05 +08:00
|
|
|
|
| 名称 | 描述 |
|
|
|
|
|
| ------- | -------- |
|
|
|
|
|
| blur() | 移除焦点 |
|
2019-11-22 14:37:39 +08:00
|
|
|
|
| focus() | 获取焦点 |
|
2019-05-17 12:05:03 +08:00
|
|
|
|
|
|
|
|
|
### Option
|
|
|
|
|
|
2022-11-25 11:12:59 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 |
|
|
|
|
|
| --------- | -------------- | ------------------- | ------ |
|
|
|
|
|
| value | 选择时填充的值 | string | - |
|
|
|
|
|
| label | 选项的标题 | React.ReactNode | - |
|
|
|
|
|
| key | 选项的 key 值 | string | - |
|
|
|
|
|
| disabled | 是否可选 | boolean | - |
|
|
|
|
|
| className | css 类名 | string | - |
|
|
|
|
|
| style | 选项样式 | React.CSSProperties | - |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
## Design Token
|
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Mentions"></ComponentTokenTable>
|