Customization

Tracked changes

Configure the DOCX editor review pane, tracked change balloons, and comment markers, or replace the balloon with your own component.

The review module shows comments and tracked changes in a review pane beside the page. This page covers where tracked changes appear and how to style or replace the tracked change balloon. Review controls require an EigenPal Pro License.

Choose where tracked changes appear

Pass pane settings to reviewModule through pane. Create the module list once, outside the component, so the editor does not receive a new module on each render:

import { DocxEditor } from '@docx-editor.dev/react';
import { reviewModule, DocxEditorReview, type ReviewPaneOptions } from '@docx-editor.dev/pro/react';

const pane: ReviewPaneOptions = { revisionsIn: 'balloons', commentMarkers: 'initials' };
const modules = [reviewModule({ pane })];

export function ReviewEditor({ bytes }: { bytes: Uint8Array }) {
  return (
    <DocxEditor.Root document={bytes} modules={modules} author="Jess Lin">
      <DocxEditor.Toolbar />
      <DocxEditor.Viewport style={{ height: 520 }}>
        <DocxEditor.Content />
        <DocxEditorReview />
      </DocxEditor.Viewport>
    </DocxEditor.Root>
  );
}

DocxEditorReview renders the pane, its cards, its markers, and the tracked change balloons. Omit a setting to keep its default.

SettingValuesDefaultEffect
revisionsIn'pane', 'balloons''pane''balloons' lists only comments in the pane and opens each tracked change in a balloon at its text.
commentMarkers'initials', 'icon''icon''initials' shows the thread author's initials, a reply count, and a check mark when resolved. An icon on DocxEditorReview.Markers overrides both values.
opening'auto', 'manual''auto''auto' opens the pane when a document with listed review items loads. With revisionsIn: 'pane', a new tracked change also opens it. 'manual' keeps the pane closed until your app or the user opens it.
overflow'float', 'shrinkPage', 'scroll''float'What the open pane does when it does not fit.

The settings belong to one editor instance. They stay in force when you load another document, and the editor never saves them into the DOCX file or shares them with collaborators. An unknown setting or value throws a TypeError when you call reviewModule.

Choose what happens when the pane does not fit

The open pane needs a 316-pixel card column beside the page. overflow decides what happens when the viewport is too narrow:

ValueThe pageThe review column
'float'Keeps its size.Changes to a marker strip. The open card floats over the page.
'shrinkPage'Shrinks under a fit zoom, down to minZoom.Stays full width while a fitting scale exists.
'scroll'Keeps its closed-pane size.Stays full width. The viewport scrolls sideways.

With a fixed zoom, 'shrinkPage' acts as 'float'. overflow does not affect the navigation pane. For zoom interaction, see Make room for the review pane.

Change pane settings at runtime

Call setReviewPaneOptions with only the settings that change, and read the settings in force from snapshot().reviewPane:

const result = editor.setReviewPaneOptions({ revisionsIn: 'balloons', overflow: 'scroll' });
if (!result.ok) console.warn('Review display refused:', result.code);

const revisionsIn = editor.snapshot().reviewPane.revisionsIn;
ResultWhen
{ ok: true, changed: false }The editor accepted the settings. changed describes the document, which a display setting never changes.
{ ok: false, code: 'invalidArgs' }Unknown setting or value.
{ ok: false, code: 'unsupported' }No review module is registered.

A refused call changes nothing. To detect a settings change, compare the snapshot().reviewPane reference. In React and Vue, read it with useEditorState((snapshot) => snapshot.reviewPane.revisionsIn).

To open or close the pane itself, call setPaneOpen from useReview(), or run the toggleReviewPane command. Read paneOpen from useReview() or snapshot().reviewPaneOpen:

const { paneOpen, setPaneOpen } = useReview();

<button onMouseDown={(event) => event.preventDefault()} onClick={() => setPaneOpen(!paneOpen)}>
  Review pane
</button>;

Set author colors and avatars

Author colors, avatars, and revision CSS tokens belong to Review colors and styling. Marks, named colors, change bars, and cell shading belong to Customize revision markup.

Style tracked change balloons

Set revisionsIn: 'balloons', then pass className to DocxEditorReview.Balloon. The part accepts only className and hidden:

<DocxEditorReview>
  <DocxEditorReview.Balloon className="contract-change-balloon" />
</DocxEditorReview>

The class lands on the balloon root. Target its card to change the visible box:

.docx-editor .contract-change-balloon .docx-review__card {
  border-radius: 12px;
  border-inline-start: 3px solid var(--doc-review-author-current);
  background: var(--doc-surface);
}
.docx-editor .contract-change-balloon .docx-review__reply-box {
  border-radius: 8px;
}

The built-in balloon shows the author, date, changed words, replies, a reply field, and Accept and Reject. Keep those controls when you restyle it.

Replace the balloon

Keep revisionsIn: 'balloons' and hide the built-in balloon. Your component then becomes the only route to each tracked change, including formatting and structural changes:

<DocxEditorReview>
  <DocxEditorReview.Balloon hidden />
</DocxEditorReview>

The following React component opens on a click or a reveal event, places itself under the change, and resolves it. Mount it in a positioned container next to DocxEditor.Viewport:

import { useEffect, useState, type RefObject } from 'react';
import { useDocxEditor, useEditorEvent } from '@docx-editor.dev/react';
import { useReview, useReviewRefusalMessage } from '@docx-editor.dev/pro/react';
import { watchBalloonAnchor, type BalloonPosition } from './watch-balloon-anchor';

// Use one query for the list and the hit test, so a replacement is one item.
const query = { pairReplacements: true };

export function MyBalloon({ container }: { container: RefObject<HTMLDivElement | null> }) {
  const editor = useDocxEditor();
  const { items, accept, reject, lastRefusal } = useReview(query);
  const refusalMessage = useReviewRefusalMessage();
  const [openKey, setOpenKey] = useState<string | null>(null);
  const [position, setPosition] = useState<BalloonPosition | null>(null);
  const item = items.find((entry) => entry.key === openKey && entry.kind === 'revision');

  // Next Change, Previous Change, and setActiveReviewItem(key, { announce: true }).
  useEditorEvent('reviewItemReveal', ({ key, pairKey }) => setOpenKey(pairKey ?? key));

  useEffect(() => {
    const host = container.current;
    if (!host || !editor) return;
    const click = (event: MouseEvent) => {
      // Read the item under the pointer. Do not call setActive: it moves the caret.
      const hit = editor
        .getReviewItemsAt(event.clientX, event.clientY, query)
        .find((entry) => entry.placement.kind === 'revision');
      setOpenKey(hit?.placement.key ?? null);
    };
    const keydown = (event: KeyboardEvent) => event.key === 'Escape' && setOpenKey(null);
    host.addEventListener('click', click);
    host.addEventListener('keydown', keydown);
    return () => {
      host.removeEventListener('click', click);
      host.removeEventListener('keydown', keydown);
    };
  }, [container, editor]);

  useEffect(() => {
    const host = container.current;
    if (!host || !editor || !item) return setPosition(null);
    return watchBalloonAnchor(editor, host, item.key, setPosition);
  }, [container, editor, item?.key]);

  if (!item || item.kind !== 'revision' || !position) return null;
  return (
    <div
      className="my-balloon"
      style={{ position: 'absolute', ...position }}
      onMouseDown={(event) => event.preventDefault()}
    >
      <strong>{item.author}</strong>
      {item.replacedText && <del>{item.replacedText}</del>}
      <p>{item.text}</p>
      <button disabled={item.readOnly} onClick={() => accept(item)}>
        Accept
      </button>
      <button disabled={item.readOnly} onClick={() => reject(item)}>
        Reject
      </button>
      {lastRefusal?.key === item.key && <p role="alert">{refusalMessage(lastRefusal)}</p>}
    </div>
  );
}

The placement helper reads getReviewItemRects(key) and refreshes after scroll, resize, document changes, zoom, and pane transitions:

import type { Editor } from '@docx-editor.dev/core';

export interface BalloonPosition {
  left: number;
  top: number;
}

export function watchBalloonAnchor(
  editor: Editor,
  host: HTMLElement,
  key: string,
  notify: (position: BalloonPosition | null) => void
): () => void {
  let frame = 0;
  const update = () => {
    frame = 0;
    const [band] = editor.getReviewItemRects(key);
    const bounds = host.getBoundingClientRect();
    // No band means no painted text, so hide the balloon.
    if (!band) return notify(null);
    notify({ left: band.left - bounds.left, top: band.bottom - bounds.top + 8 });
  };
  const schedule = () => {
    if (!frame) frame = requestAnimationFrame(update);
  };
  update();
  const resize = new ResizeObserver(schedule);
  resize.observe(host);
  host.addEventListener('scroll', schedule, true);
  host.addEventListener('transitionend', schedule);
  const offChange = editor.on('change', schedule);
  let { zoom, reviewPaneOpen } = editor.snapshot();
  const offView = editor.on('selectionChange', (snapshot) => {
    if (snapshot.zoom === zoom && snapshot.reviewPaneOpen === reviewPaneOpen) return;
    ({ zoom, reviewPaneOpen } = snapshot);
    schedule();
  });
  return () => {
    cancelAnimationFrame(frame);
    resize.disconnect();
    host.removeEventListener('scroll', schedule, true);
    host.removeEventListener('transitionend', schedule);
    offChange();
    offView();
  };
}

In Vue, use the same calls: useReview(query), useEditorEvent, and watchEffect with onCleanup for the listeners and the placement helper.

NeedAPI
Item under a clickeditor.getReviewItemsAt(clientX, clientY, query), innermost first.
Balloon positioneditor.getReviewItemRects(key), in client coordinates.
Follow navigationreviewItemReveal. Open pairKey ?? key, or key if your query excludes 'replace'.
Explicit activationuseReview().activatedKey.
Refusal textlastRefusal with useReviewRefusalMessage().
Changes left after a bulk decisionreviewChangesResolved event skipped, with reviewCodeOfSkip(skip) from @docx-editor.dev/core.

For replacement pairing, see Show a replacement as one item. For refusal codes, see Diagnostics.

Limits

  • Tracked change balloons open only in All Markup.
  • Moving the caret into a change does not open its balloon. Do not open your balloon from activeKey, which follows the caret.
  • Escape, typing in the document, or a click elsewhere closes the built-in balloon.
  • With revisionsIn: 'balloons', a document with tracked changes and no comments does not open the pane.
  • Switching to 'balloons' closes an open pane that has nothing left to list.
  • With opening: 'manual', Next Change and Previous Change do not open the pane.
  • Hiding the built-in balloon also removes balloon access to formatting and structural changes. Handle every revision kind.
  • Check the Boolean that accept and reject return.
  • Comment initials show at most three characters. An empty author name shows ?.

See also