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} />;
}Create ContractPageSetup.vue:
<script setup lang="ts">
import { DocxEditorPageSetupDialog as Dialog } from '@docx-editor.dev/vue';
import type { DocxEditorPageSetupDialogProps } from '@docx-editor.dev/vue';
const props = withDefaults(defineProps<DocxEditorPageSetupDialogProps>(), {
preset: true,
});
</script>
<template>
<Dialog v-bind="props">
<Dialog.Title>Contract page setup</Dialog.Title>
<Dialog.Apply as-child>
<button type="button" class="contract-apply">Apply page settings</button>
</Dialog.Apply>
</Dialog>
</template>Register the wrapper in your editor component:
<script setup lang="ts">
import { DocxEditor, definePopup } from '@docx-editor.dev/vue';
import ContractPageSetup from './ContractPageSetup.vue';
defineProps<{ bytes: Uint8Array }>();
const popups = { pageSetup: definePopup(ContractPageSetup) };
</script>
<template>
<DocxEditor :document="bytes" :popups="popups" />
</template>Vue wrappers must keep the preset: true default when they forward omitted Boolean props.
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>| Prop | Effect |
|---|---|
className, style | Styles 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.
| Member | Use |
|---|---|
values, setValue, errors | Draft fields and their validation messages. |
isEnabled | Whether Apply can run. |
apply, cancel | Validate and commit, or discard, the draft. |
reset | Revision 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
falseentry onexportorprintdisables feedback only. The operation still runs, so your handlers must report errors. - A
falseentry 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
popupsentry overrides packaged shortcut props. - In a composed editor, you render the hyperlink, content control, equation, and context menu surfaces yourself, unless
popupsconfigures 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.