Skip to main content

Setup

Step 1: Add Comment components

  • Add the Velt Comments component to the root of your app.
  • This component is required to render comments in your app.
  • Set the text mode prop to false to hide the default text comment tool.

Step 2: Install the Velt DraftJS extension

Step 3: Configure the DraftJS editor with the Velt Comments extension

Use DraftJSVeltEditor instead of the standard DraftJS Editor. This wrapper component handles the DraftJS decorator setup, content change detection, and annotation tracking.

Step 4: Add a comment button to your DraftJS editor

  • Add a button that users can click after selecting text in the DraftJS editor.
  • Use onMouseDown with preventDefault() so the browser does not move focus away from the editor and clear the current text selection.

Step 5: Call addComment to add a comment

  • Call this method to add a comment to selected text in the DraftJS editor.
  • Params: AddCommentRequest
    • editor: DraftJS editor wrapper object with { editorState, setEditorState }.
    • editorId: Id of the editor. Use this if you have multiple DraftJS editors on the same page. (optional)
    • context: Add custom metadata to the Comment Annotation. Learn more. (optional)

Step 6: Render comments in DraftJS editor

  • Get comment data from Velt SDK and render it in the DraftJS editor.
  • Params: RenderCommentsRequest
    • editor: DraftJS editor wrapper object with { editorState, setEditorState }.
    • editorId: Id of the editor. Use this if you have multiple DraftJS editors on the same page. (optional)
    • commentAnnotations: Array of Comment Annotation objects.

Step 7: Persist DraftJS content without Velt comment entities (optional)

  • When saving editor content to your backend, remove Velt comment entities to keep your stored content clean.
  • Use exportContentStateWithoutComments before converting DraftJS content to raw JSON.

Step 8: Style the commented text

  • Style the commented text by adding CSS for the velt-comment-text element.

Complete Example

APIs

DraftJSVeltEditor

A wrapper around the DraftJS Editor component that automatically handles decorator setup, content change detection, and Velt annotation context updates.
  • Props: DraftJSVeltEditorProps
    • editorState: Current DraftJS editor state.
    • onChange: Callback when the editor state changes.
    • editorId: Optional editor ID for multi-editor scenarios.
    • All other standard DraftJS Editor props are forwarded.

addComment()

Creates a comment annotation for the currently selected text in the editor.

renderComments()

Renders and highlights comment annotations in the DraftJS editor.

exportContentStateWithoutComments()

Returns a DraftJS ContentState without Velt comment entities. Use it before saving content outside Velt.