Mention
Enable autocompletion for user mentions.
components/demo.tsx
'use client';
import React from 'react';
import { Plate } from '@udecode/plate-common/react';
import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = useCreateEditor({
plugins: [...editorPlugins],
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
安装
npm install @udecode/plate-mention
用法
import { MentionPlugin } from '@udecode/plate-mention/react';
const plugins = [
// ...otherPlugins,
MentionPlugin,
];
插件
MentionPlugin
Options
Collapse all
是否在提及后插入空格。
MentionInputPlugin
提及输入功能的插件。
API
editor.api.insert.mention
重写此 API 方法以自定义提及的插入方式。
getMentionOnSelectItem
获取提及组合框中选择项目的处理程序。
Parameters
Collapse all
Returns
Collapse all
提及组合框中选择项目的处理程序。