JGuang

Mentions

Mentions · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

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

PropertyDescriptionTypeDefaultVersionGlobal Config
allowClearWhether to show a clear icon to remove mentions contentboolean | { clearIcon?: ReactNode, disabled?: boolean }false5.13.0, disabled: 6.4.06.4.0
autoSizeTextarea height autosize feature, can be set to true | false or an object { minRows: 2, maxRows: 6 }boolean | objectfalse×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
defaultValueDefault valuestring-×
filterOptionCustomize filter option logicfalse | (input: string, option: OptionProps) => boolean-×
getPopupContainerSet the mount HTML node for suggestions() => HTMLElement-×
notFoundContentSet mentions content when not matchReactNodeNo data×
placementSet popup placementtop | bottombottom×
popupRenderCustomize the dropdown menu rendering(menu: React.ReactElement) => ReactNode-6.6.0×
prefixSet trigger prefix keywordstring | string[]@×
splitSet split string before and after selected mentionstring ×
sizeThe size of the input boxlarge | medium | small-×
statusSet validation status'error' | 'warning' | 'success' | 'validating'-4.19.0×
validateSearchCustomize trigger search logic(text: string, props: MentionsProps) => void-×
valueSet value of mentionsstring-×
variantVariants of Inputoutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.05.19.0
onBlurTrigger when mentions lose focus() => void-×
onChangeTrigger when value changed(text: string) => void-×
onClearCallback when click the clear button() => void-5.20.0×
onFocusTrigger when mentions get focus() => void-×
onResizeThe callback function that is triggered when textarea resizefunction({ width, height })-×
onSearchTrigger when prefix hit(text: string, prefix: string) => void-×
onSelectTrigger when user select the option(option: OptionProps, prefix: string) => void-×
onPopupScrollTrigger when mentions scroll(e: Event) => void-5.23.0×
optionsOption ConfigurationOptions[]5.1.0×
stylesCustomize 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

NameDescription
blur()Remove focus
focus()Get focus

Option

PropertyDescriptionTypeDefault
valueValue inserted when selectedstring-
labelTitle of the optionReact.ReactNode-
keyThe key value of the optionstring-
disabledOptionalboolean-
classNameclassNamestring-
styleThe style of the optionReact.CSSProperties-

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element, set inline flex layout, relative positioning, padding and border styles6.0.0
textareaTextarea element, set font, line height, text input and background styles6.0.0
suffixSuffix element with layout and styling for suffix content like clear button, etc.6.0.0
popupPopup element, set absolute positioning, z-index, background color, border radius, shadow and dropdown options styles6.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.

TokenTypeNative description
zIndexPopupnumberz-index of popup
dropdownHeightnumber | stringHeight of popup
controlItemWidthnumber | stringHeight 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.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

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.tsx
  • vendor/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.