2019-05-17 12:05:03 +08:00
---
category: Components
2022-11-09 12:28:04 +08:00
group: Data Entry
2019-05-17 12:05:03 +08:00
title: Mentions
2024-03-22 14:22:42 +08:00
description: Used to mention someone or something in an input.
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
---
## When To Use
2021-07-19 16:21:09 +08:00
When you need to mention someone or something.
2019-05-17 12:05:03 +08:00
2022-11-21 21:34:23 +08:00
### Usage upgrade after 5.1.0
2024-01-05 10:12:22 +08:00
<!-- prettier - ignore -->
2024-04-07 17:02:59 +08:00
:::info{title="Upgrade Tip"}
2024-01-05 10:12:22 +08:00
After version 5.1.0, we provide a simpler usage `<Mentions options={[...]} />` with better performance and potential of writing simpler code style in your applications.
Meanwhile, we deprecated the old usage in browser console, we will remove it in antd 6.0.
:::
2019-05-17 12:05:03 +08:00
```jsx
2022-11-21 21:34:23 +08:00
// works when >=5.1.0, recommended ✅
const options = [{ value: 'sample', label: 'sample' }];
return < Mentions options = {options} / > ;
// works when < 5.1.0 , deprecated when > =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
## Examples
<!-- prettier - ignore -->
< code src = "./demo/basic.tsx" > Basic< / code >
2023-12-18 17:53:31 +08:00
< code src = "./demo/variant.tsx" version = "5.13.0" > Variants< / code >
2023-02-04 21:26:12 +08:00
< code src = "./demo/async.tsx" > Asynchronous loading< / code >
< code src = "./demo/form.tsx" > With Form< / code >
< code src = "./demo/prefix.tsx" > Customize Trigger Token< / code >
< code src = "./demo/readonly.tsx" > disabled or readOnly< / code >
< code src = "./demo/placement.tsx" > Placement< / code >
2023-12-25 10:37:26 +08:00
< code src = "./demo/allowClear.tsx" > With clear icon< / code >
2023-02-04 21:26:12 +08:00
< code src = "./demo/autoSize.tsx" > autoSize< / code >
< code src = "./demo/status.tsx" > Status< / 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 > Component 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
Common props ref: [Common props](/docs/react/common-props)
2019-05-17 12:05:03 +08:00
### Mention
2022-02-16 21:14:05 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2023-12-25 10:37:26 +08:00
| allowClear | Show clear button | boolean \| { clearIcon?: ReactNode } | false | 5.13.0 |
2022-02-16 21:14:05 +08:00
| autoFocus | Auto get focus when component mounted | boolean | false | |
| autoSize | Textarea height autosize feature, can be set to true \| false or an object { minRows: 2, maxRows: 6 } | boolean \| object | false | |
| defaultValue | Default value | string | - | |
| filterOption | Customize filter option logic | false \| (input: string, option: OptionProps) => boolean | - | |
| getPopupContainer | Set the mount HTML node for suggestions | () => HTMLElement | - | |
| notFoundContent | Set mentions content when not match | ReactNode | `Not Found` | |
| placement | Set popup placement | `top` \| `bottom` | `bottom` | |
| prefix | Set trigger prefix keyword | string \| string\[] | `@` | |
| split | Set split string before and after selected mention | string | ` ` | |
| status | Set validation status | 'error' \| 'warning' \| 'success' \| 'validating' | - | 4.19.0 |
| validateSearch | Customize trigger search logic | (text: string, props: MentionsProps) => void | - | |
| value | Set value of mentions | string | - | |
2023-12-18 17:53:31 +08:00
| variant | Variants of Input | `outlined` \| `borderless` \| `filled` | `outlined` | 5.13.0 |
2022-02-16 21:14:05 +08:00
| onBlur | Trigger when mentions lose focus | () => void | - | |
| onChange | Trigger when value changed | (text: string) => void | - | |
| onFocus | Trigger when mentions get focus | () => void | - | |
| onResize | The callback function that is triggered when textarea resize | function({ width, height }) | - | |
| onSearch | Trigger when prefix hit | (text: string, prefix: string) => void | - | |
| onSelect | Trigger when user select the option | (option: OptionProps, prefix: string) => void | - | |
2022-12-22 14:12:26 +08:00
| options | Option Configuration | [Options ](#option ) | \[] | 5.1.0 |
2019-05-17 12:05:03 +08:00
### Mention methods
2022-02-16 21:14:05 +08:00
| Name | Description |
| ------- | ------------ |
| blur() | Remove focus |
| focus() | Get focus |
2019-05-17 12:05:03 +08:00
### Option
2022-12-05 14:15:26 +08:00
<!-- prettier - ignore -->
2019-11-22 14:37:39 +08:00
| Property | Description | Type | Default |
| --- | --- | --- | --- |
2022-11-21 21:34:23 +08:00
| label | Title of the option | React.ReactNode | - |
| key | The key value of the option | string | - |
| disabled | Optional | boolean | - |
| className | className | string | - |
| style | The style of the option | React.CSSProperties | - |
2023-04-11 10:25:24 +08:00
## Design Token
< ComponentTokenTable component = "Mentions" > < / ComponentTokenTable >