Framework bindings
All bindings mount <docx-editor> through the same mountEditor function. A property assignment is an external document replacement, not an edit event. document-change carries a DocumentModel directly; document-error carries an Error. Both events bubble across the shadow boundary.
React:
import { WordEditor } from 'docx-react-viewer';
<WordEditor documentModel={model} readOnly={false} onDocumentChange={setModel} />;ref exposes element, load(bytes), save(), download(), markClean(), openCloudFile() and dirty.
Vue:
<script setup>
import { WordEditor } from 'docx-vue-viewer';
</script>
<template>
<WordEditor :document-model="model" @document-change="model = $event" />
</template>Angular:
import { WordEditorComponent } from 'docx-angular-viewer';
// Add WordEditorComponent to your standalone component imports.<word-editor [documentModel]="model" [readOnly]="false" (documentChange)="model = $event" />Svelte 5:
<script>
import WordEditor from 'docx-svelte-viewer';
let model = $state(initialDocument);
</script>
<WordEditor documentModel={model} ondocumentchange={next => model = next} />SolidJS:
import { createSignal } from 'solid-js';
import { WordEditor } from 'docx-solid-viewer';
function DocumentEditor() {
const [model, setModel] = createSignal(initialDocument);
return <WordEditor documentModel={model()} onDocumentChange={setModel} />;
}Solid uses the same documentModel, readOnly, locale, onDocumentChange, and onDocumentError options as the shared adapter. Use editorRef to obtain the mounted editor's element, load, and save methods. The Solid owner cleans up the editor and its listeners when the component unmounts.
Custom element:
import { registerDocxEditor } from 'docx-vanilla-viewer';
registerDocxEditor();
const element = document.createElement('docx-editor');
element.documentModel = model;
document.body.append(element);The vanilla mount adapter is exported from docx-vanilla-viewer and returns update, destroy, load, save, and element operations. It avoids feedback resets when a parent returns the emitted model. Supply a new object for external model changes; mutating a model in place is not a supported reactivity mechanism.
Framework packages use their own native lifecycle and ref APIs. No framework template contains a toolbar, page renderer or document command implementation. SSR imports do not register elements; mounting is a client operation. The current browser contract validates the installed versions, not every historical peer version.
Set the optional locale prop on any framework editor to localize the ribbon and search controls (en, fr, de, es or zh-CN; for example, locale="de"). This affects interface text only; it does not translate document content.
Window chrome and file commands
The editor draws Word-style chrome inside its shadow root: a title bar (quick-access Save, Undo and Redo, the file name and save state, a "Tell me what you want to do" command search), the Editing/Viewing mode switch, Comments and Share at the right end of the ribbon tab row (as in Word 365), a File tab with a backstage (Info with compatibility notes, New, Open, Save, Save a copy as DOCX, Print), and a status bar (page, words, compatibility notes, Web/Print Layout and zoom).
Set element.fileName to name the open document. File commands are announced first as a cancelable file-command event whose detail.command is new, open, save, saveAs, export, exportText, exportPdf, print or share. Call preventDefault() to handle it in your application (for example to save to your own storage); otherwise the editor uses its browser-only default: a file picker, a download, or the print dialog. share (the Share button) opens the Share dialog every Office editor uses: start a session (session name, your name and an optional server) or join one from an invitation link or session name, then copy the invitation link, see who is in the session and stop sharing, which sets the collaboration property; cancel it to share your own way. Choosing Viewing raises readonly-change.
editor.fileName = 'Quarterly report.docx';
editor.addEventListener('file-command', (event) => {
const { command } = (event as CustomEvent<{ command: string }>).detail;
if (command === 'save') {
event.preventDefault();
void editor.save().then(uploadToMyStorage);
}
});Saving, dirty state and UI options
save() resolves to a Blob of the serialized document (saveBytes() returns the raw Uint8Array), download(fileName?) saves and starts a browser download, and dirty / dirty-change report unsaved edits. dirty becomes true on document-change and false after File > Save, download(), loading a document or markClean(); save() alone does not clear it because only the host knows whether the Blob was persisted. Every adapter exposes save, download, markClean and dirty on its handle and onDirtyChange / onPageChange (or the framework's event equivalent).
| Property (attribute) | Default | Effect |
|---|---|---|
showThumbnails (show-thumbnails) | false | Left rail of page thumbnails. Thumbnails need Print Layout; in Draft view the rail says so instead of listing pages. |
readAloud | null | Read Aloud options. stopOnEdit (default false) also stops playback when the document is edited; replacing, loading or unmounting always stops it. |
showToolbar (show-toolbar) | true | show-toolbar="false" hides the ribbon; the title bar and status bar remain. |
hiddenActions | [] | Ribbon controls to hide by stable kebab-case id (RIBBON_ACTION_IDS, e.g. 'bold', 'insert-table', 'track-changes', 'paste', 'word-count'); empty groups and tabs hide too. A colour button and its dropdown caret hide together. Unknown ids are ignored. Ids do not change with locale. |
ribbonAddIns | none | Tabs the host adds after the built-in ones; see Ribbon add-in tabs. |
Deprecated: before ids existed hiddenActions took the English control label ('Bold', 'Insert table'). Those LegacyRibbonLabel strings are still accepted for one more release: they are mapped to ids and the element dispatches one document-warning per assignment. Reading hiddenActions always returns ids. ribbon-action events never carried labels (their detail is keyed by command type), so they are unchanged.
page-change ({ page, pageCount }) fires from Print Layout only. Pagination comes from this editor's own layout engine and is an approximation, not Word's pagination; the status bar and rail tooltips say so.
Ribbon add-in tabs
A host can add its own ribbon tabs after Word's own, as an Office add-in does. ribbonAddIns takes plain data and is a prop of every binding; a chosen command runs its run callback and is reported through onRibbonAddIn (Vue office-ribbon-add-in, Angular ribbonAddIn, Svelte onribbonaddin) with { tab, command }.
const tabs = [
{
id: 'reports',
label: 'Reports',
groups: [
{
label: 'Export',
commands: [
{ id: 'export', label: 'Export', icon: 'save', run: () => exportReport() },
{ id: 'options', label: 'Options', size: 'small' },
{ id: 'send', label: 'Send', items: [{ id: 'send-mail', label: 'By mail' }] },
],
},
],
},
];
<WordEditor ribbonAddIns={tabs} onRibbonAddIn={({ tab, command }) => track(tab, command)} />;size: 'small' commands fill columns of three and items makes a drop-down. Passing an equal descriptor again, as a framework does on every render, keeps the panels and only replaces the callbacks; leaving the prop out removes the tabs. A tab cannot take the id of a built-in tab, and its commands never reach the editor's own command handling. The same descriptor (RibbonAddInTab, from ooxml-core/ribbon, re-exported by every framework package) works in the Word, Excel, PowerPoint and Visio editors. No add-in tab ships with the editor.
Binding props and events
Every framework adapter forwards the same element props and re-emits the same events, so the names below mean one thing in every binding. The event names are the element's (file-command); each framework spells them in its own idiom.
| Element prop | React / Solid / Vanilla | Vue prop | Angular input | Svelte prop |
|---|---|---|---|---|
fileName | fileName | fileName | fileName | fileName |
reviewAuthor | reviewAuthor | reviewAuthor | reviewAuthor | reviewAuthor |
themeColors | themeColors | themeColors | themeColors | themeColors |
fileName, reviewAuthor and themeColors are forwarded when the prop is set or changes, so a rename made by File > Open is not reverted by a re-render that passes the old name.
| Element event | React / Solid / Vanilla option | Vue event | Angular output | Svelte callback |
|---|---|---|---|---|
file-command | onFileCommand(event) | file-command | fileCommand | onfilecommand |
document-warning | onDocumentWarning(message) | document-warning | documentWarning | ondocumentwarning |
readonly-change | onReadOnlyChange(readOnly) | readonly-change | readOnlyChange | onreadonlychange |
ribbon-action | onRibbonAction(detail) | ribbon-action | ribbonAction | onribbonaction |
ribbon-customize | onRibbonCustomize(ids) | ribbon-customize | ribbonCustomize | onribboncustomize |
file-command is the one cancelable event, so its handler receives the event itself rather than its detail. Call event.preventDefault() to take a File command over (Save, Open, New and so on); event.detail.command says which one. The Vue, Angular and Svelte handlers receive the same CustomEvent object. The other events pass their detail directly.