
Setup
Step 1: Add Comment components
- Add the
Velt Commentscomponent to the root of your app. - This component is required to render comments in your app.
- Set the
text modeprop tofalseto hide the default text comment tool.
- React / Next.js
- Other Frameworks
Step 2: Install the Velt Lexical extension
Step 3: Configure the Lexical editor with the Velt Comments extension
- Register the
CommentNodeand configure your Lexical editor.
- React / Next.js
- Other Frameworks
Step 4: Add a comment button
- Add a button that users can click to add comments after selecting text.
- React / Next.js
- Other Frameworks
Step 5: Call addComment to add a comment
- Call this method to add a comment to selected text in the Lexical editor. You can use this when the user clicks on a comment button or presses a keyboard shortcut.
- Params:
AddCommentRequest. It has the following properties:editor: Instance of the Lexical Editor.editorId: Id of the editor. Use this if you have multiple Lexical editors on the same page. (optional)context: Add any custom metadata to the Comment Annotation. Learn more. (optional)
- React / Next.js
- Other Frameworks
Step 6: Render comments in Lexical editor
- Get the comment data from Velt SDK and render it in the Lexical Editor.
- Params:
RenderCommentsRequest. It has the following properties:editor: Instance of the Lexical Editor.editorId: Id of the editor. Use this if you have multiple Lexical editors on the same page. (optional)commentAnnotations: Array of Comment Annotation objects.
- React / Next.js
- Other Frameworks
Step 7: Persist Editor Content Without Velt Marks (optional)
- When saving editor content to your backend, you may want to exclude Velt comment marks to keep the content clean.
- Use
exportJSONWithoutCommentsto export the editor state as JSON without Velt comment nodes.
Step 8: Style the commented text
- Style the commented text by adding CSS for the
velt-comment-textelement.
Complete Example
APIs
CommentNode
A custom Lexical node used to wrap commented text with comment annotation metadata.- Usage: Register the node with your Lexical editor so comment elements render correctly.
- React / Next.js
- Other Frameworks
addComment()
Creates a comment annotation for the currently selected text in the editor.- Params:
request:AddCommentRequesteditor: LexicalEditoreditorId?: stringcontext?: object
- Returns:
Promise<void>
- React / Next.js
- Other Frameworks
renderComments()
Renders and highlights comment annotations in the editor.- Params:
request:RenderCommentsRequesteditor: LexicalEditoreditorId?: stringcommentAnnotations?:CommentAnnotation[]
- Returns:
void
- React / Next.js
- Other Frameworks
exportJSONWithoutComments()
Exports the editor state as serialized JSON while stripping out all comment nodes and normalizing adjacent text nodes.- Params:
editor:LexicalEditor - Returns:
SerializedEditorState

