Mentions
Used to mention someone or something in an input.
When To Use
When you need to mention someone or something.
Examples
-
Basic ·
basic -
Size ·
size -
Variants ·
variant -
Asynchronous loading ·
async -
With Form ·
form -
Customize Trigger Token ·
prefix -
disabled or readOnly ·
readonly -
Placement ·
placement -
Customize Popup ·
popupRender -
With clear icon ·
allowClear -
autoSize ·
autoSize -
Status ·
status -
Custom semantic dom styling ·
style-class
API
Common props ref:Common props
Mention
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| allowClear | Whether to show a clear icon to remove mentions content | boolean | { clearIcon?: ReactNode, disabled?: boolean } | false | 5.13.0, disabled: 6.4.0 | 6.4.0 |
| autoSize | Textarea height autosize feature, can be set to true | false or an object { minRows: 2, maxRows: 6 } | boolean | object | false | × | |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 6.0.0 | |
| 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 | No data | × | |
| placement | Set popup placement | top | bottom | bottom | × | |
| popupRender | Customize the dropdown menu rendering | (menu: React.ReactElement) => ReactNode | - | 6.6.0 | × |
| prefix | Set trigger prefix keyword | string | string[] | @ | × | |
| split | Set split string before and after selected mention | string | | × | |
| size | The size of the input box | large | medium | small | - | × | |
| 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 | - | × | |
| variant | Variants of Input | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 | 5.19.0 |
| onBlur | Trigger when mentions lose focus | () => void | - | × | |
| onChange | Trigger when value changed | (text: string) => void | - | × | |
| onClear | Callback when click the clear button | () => void | - | 5.20.0 | × |
| 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 | - | × | |
| onPopupScroll | Trigger when mentions scroll | (e: Event) => void | - | 5.23.0 | × |
| options | Option Configuration | Options | [] | 5.1.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 6.0.0 |
Mention methods
| Name | Description |
|---|---|
| blur() | Remove focus |
| focus() | Get focus |
Option
| Property | Description | Type | Default |
|---|---|---|---|
| value | Value inserted when selected | string | - |
| 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 | - |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element, set inline flex layout, relative positioning, padding and border styles | 6.0.0 |
textarea | Textarea element, set font, line height, text input and background styles | 6.0.0 |
suffix | Suffix element with layout and styling for suffix content like clear button, etc. | 6.0.0 |
popup | Popup element, set absolute positioning, z-index, background color, border radius, shadow and dropdown options styles | 6.0.0 |
Semantic description source: vendor/components/mentions/demo/_semantic.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
zIndexPopup | number | z-index of popup |
dropdownHeight | number | string | Height of popup |
controlItemWidth | number | string | Height of menu item |
Declaration source: vendor/components/mentions/style/index.ts
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import {
genBasicInputStyle,
genPlaceholderStyle,
initComponentToken,
initInputToken,
} from '../../input/style';
import type { SharedComponentToken, SharedInputToken } from '../../input/style/token';
import {
genBorderlessStyle,
genDisabledStyle,
genFilledStyle,
genOutlinedStyle,
genUnderlinedStyle,
} from '../../input/style/variants';
import { resetComponent, textEllipsis } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
import { genCssVar } from '../../theme/util/genStyleUtils';
export interface ComponentToken extends SharedComponentToken {
/**
* @desc 弹层 z-index
* @descEN z-index of popup
*/
zIndexPopup: number;
/**
* @desc 弹层高度
* @descEN Height of popup
*/
dropdownHeight: number | string;
/**
* @desc 菜单项高度
* @descEN Height of menu item
*/
controlItemWidth: number | string;
}
/**
* @desc Mentions 组件的 Token
* @descEN Token for Mentions component
*/
type MentionsToken = FullToken<'Mentions'> &
SharedInputToken & {
/**
* @desc 菜单项内边距
* @descEN Padding of menu item
*/
itemPaddingVertical: string | number;
};
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/mentions/index.tsxvendor/components/mentions/style/index.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.