Customization

Dialogs

Replace DOCX editor dialogs and popups with your own components while keeping draft state, validation, and focus.

Register your component with definePopup() and pass the map through popups. Your wrapper keeps the packaged draft, validation, and focus handling.

Register a custom dialog

This wrapper retitles page setup and replaces its Apply button. Forward the supplied props to keep the session.

import { DocxEditor, definePopup } from '@docx-editor.dev/react';
import type { DocxEditorPageSetupDialogProps, DocxEditorPopups } from '@docx-editor.dev/react';

export function ContractPageSetup(props: DocxEditorPageSetupDialogProps) {
  return (
    <DocxEditor.PageSetupDialog {...props}>
      <DocxEditor.PageSetupDialog.Title>Contract page setup</DocxEditor.PageSetupDialog.Title>
      <DocxEditor.PageSetupDialog.Apply asChild>
        <button type="button" className="contract-apply">
          Apply page settings
        </button>
      </DocxEditor.PageSetupDialog.Apply>
    </DocxEditor.PageSetupDialog>
  );
}

const popups: DocxEditorPopups = { pageSetup: definePopup(ContractPageSetup) };

export function ContractDialogEditor({ bytes }: { bytes: Uint8Array }) {
  return <DocxEditor document={bytes} popups={popups} />;
}

DocxEditor.Root takes the same popups prop. Other keys include paragraph, revisionMarkup, hyperlink, export, and print. For every popup key, see Customize popups.

Replace dialog parts

Standard dialogs expose Header, Title, Body, Footer, Field, Error, Apply, and Cancel. The revision markup dialog adds Reset. The compare documents dialog adds Progress and Notice.

<DocxEditor.PageSetupDialog {...props}>
  <DocxEditor.PageSetupDialog.Field name="scope" hidden />
</DocxEditor.PageSetupDialog>
PropEffect
className, styleStyles the dialog root or a part.
preset (root)true by default. false renders only your arrangement.
hidden (part)Removes the part.
asChild (part)Applies the part's wiring to one custom child.
name (Field)Selects the field to replace or hide.
id, title, aria-label, data-* (part)Extra attributes.

Part wiring wins over conflicting props. Custom children must forward attributes, events, and refs. For dialog tokens, see Appearance.

Connect draft inputs

Custom inputs write to the dialog's draft controller, not the document. The paragraph controller also reports mixed values.

MemberUse
values, setValue, errorsDraft fields and their validation messages.
isEnabledWhether Apply can run.
apply, cancelValidate and commit, or discard, the draft.
resetRevision markup controller only.

Page setup drafts store pageWidth, pageHeight, marginTop, marginBottom, marginLeft, and marginRight in twips. orientation is portrait or landscape, and scope is document or section.

Packaged inputs display inches and convert to twips (1440 per inch).

Limits

  • A false entry on export or print disables feedback only. The operation still runs, so your handlers must report errors.
  • A false entry on another popup can disable its controls until you register another view. For example, the link control stays disabled without a hyperlink view.
  • An explicit popups entry overrides packaged shortcut props.
  • In a composed editor, you render the hyperlink, content control, equation, and context menu surfaces yourself, unless popups configures them.
  • A session ends when a document loads, the editor detaches, or a new session starts. Check its cancellation signal before applying an async result.
  • Do not keep a draft controller after its dialog closes.
  • A full custom arrangement must keep a title, error region, Apply, and Cancel.
  • An application modal must trap and restore focus like the built-in surface.

See also