content/docs/(plugins)/(elements)/mention.mdx
Mention turns trigger text such as @ into an inline combobox input and inserts a markable void mention node when the user selects an item. The package owns trigger detection, input node creation, mention insertion, selection movement, and Markdown mention serialization. The registry owns the demo item list and the inline combobox UI.
mention nodes with value and optional key.mention_input nodes created by trigger text.@platejs/combobox.[display text](mention:id) plus bare @name deserialization.MentionKit installs MentionPlugin, MentionInputPlugin, the registry mention nodes, and a trigger rule that allows @ at the start of a line, after whitespace, or after quotes.
import { createPlateEditor } from 'platejs/react';
import { MentionKit } from '@/components/editor/plugins/mention-kit';
export const editor = createPlateEditor({
plugins: MentionKit,
});
mention-node renders both the selected mention and the temporary combobox input. The demo data lives in that registry UI file, so replace it with your app users, pages, or records.
mention-base-kit uses BaseMentionPlugin with the static mention node for read-only output.
| Layer | Owner | What It Does |
|---|---|---|
@platejs/mention | Package | Exports BaseMentionPlugin, BaseMentionInputPlugin, and getMentionOnSelectItem. |
@platejs/mention/react | Package | Exports MentionPlugin and MentionInputPlugin. |
@platejs/combobox | Package | Provides withTriggerCombobox, trigger options, and combobox input hooks. |
mention-kit | Registry | Adds mention plugins with editable mention and input components. |
mention-base-kit | Registry | Adds BaseMentionPlugin.withComponent(MentionElementStatic). |
mention-node | Registry UI | Renders mention atoms, the inline combobox input, and demo items. |
inline-combobox | Registry UI | Renders the Ariakit-backed popover, input, groups, items, and empty state. |
@platejs/markdown | Package | Serializes mentions as mention: links and deserializes mention links or bare mentions. |
npm install @platejs/mention
Configure the mention plugin with the trigger behavior and render both node types.
import { MentionInputPlugin, MentionPlugin } from '@platejs/mention/react';
import { createPlateEditor } from 'platejs/react';
import {
MentionElement,
MentionInputElement,
} from '@/components/ui/mention-node';
export const editor = createPlateEditor({
plugins: [
MentionPlugin.configure({
options: {
triggerPreviousCharPattern: /^$|^[\s"']$/,
},
}).withComponent(MentionElement),
MentionInputPlugin.withComponent(MentionInputElement),
],
});
Use getMentionOnSelectItem from your combobox item renderer. It inserts the mention, moves the cursor after it, and inserts a trailing space only when insertSpaceAfterMention is enabled and the mention lands at the end of the block.
import { getMentionOnSelectItem } from '@platejs/mention';
const onSelectItem = getMentionOnSelectItem();
<InlineComboboxItem
value={item.text}
onClick={() => onSelectItem(editor, item, search)}
>
{item.text}
</InlineComboboxItem>;
BaseMentionPlugin uses KEYS.mention, which resolves to the mention node type. The input plugin uses KEYS.mentionInput, which resolves to mention_input.
const value = [
{
children: [
{ text: 'Assigned to ' },
{
children: [{ text: '' }],
key: 'user_123',
type: 'mention',
value: 'Jane Smith',
},
{ text: '.' },
],
type: 'p',
},
];
| Field | Type | Notes |
|---|---|---|
type | 'mention' | Inline void mention node. |
value | string | Display text rendered by the registry node. |
key | unknown | Optional stable id used by selection handlers and Markdown serialization. |
children | [{ text: '' }] | Empty child required for Slate inline void nodes. |
The mention node is isMarkableVoid, so marks on its empty child can style the rendered mention.
withTriggerCombobox overrides insertText. It creates a combobox input only when every gate passes.
| Gate | Source |
|---|---|
Inserted text matches trigger | string, string[], or RegExp. |
Insert is not using options.at | Programmatic text insertion bypasses the trigger. |
| Editor has a selection | No selection means no inline input target. |
triggerQuery(editor) returns true | Optional app veto for custom contexts. |
Previous character matches triggerPreviousCharPattern | Defaults to /^\s?$/; registry kit uses /^$|^[\s"']$/. |
The default createComboboxInput creates:
{
children: [{ text: '' }],
trigger: '@',
type: KEYS.mentionInput,
}
If editor.meta.userId exists, the combobox input stores that userId so only the creator sees the transient input in collaborative editors.
@platejs/markdown serializes mentions as link-style mention: URLs. It uses key for the URL when present and value for the visible text.
Hello [Jane Smith](mention:user_123).
Deserialization supports link-style mentions and bare @alice text. Normal links such as [@docs](/docs/mention) stay links.
| API | Package | Use |
|---|---|---|
BaseMentionPlugin | @platejs/mention | Headless inline markable void mention plugin with trigger-combobox behavior. |
BaseMentionInputPlugin | @platejs/mention | Inline void input node inserted while the combobox is active. |
MentionPlugin | @platejs/mention/react | React mention plugin. |
MentionInputPlugin | @platejs/mention/react | React mention input plugin. |
editor.tf.insert.mention({ key, value }) | BaseMentionPlugin transform | Inserts the mention node at the current selection. |
getMentionOnSelectItem({ key? }) | @platejs/mention | Returns an item handler for mention combobox selection. |
withTriggerCombobox | @platejs/combobox | Creates temporary combobox input nodes from trigger text. |
useComboboxInput | @platejs/combobox/react | Handles focus, cancellation, arrow/backspace/escape behavior, and undo/redo forwarding for custom input UI. |