DocEditor
A word-processor style document editor with headings, text formatting, lists, quotes and alignment, and a download as a Word (.docx) file.
Installation
npx dafink-ui add doc-editorAlso installs: Button, Select, Icons
Requires: @tiptap/react, @tiptap/starter-kit, @tiptap/extension-text-align, jszip
Demo
Props
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | - | Required. The document as HTML (headings, paragraphs, lists, quotes). Pass the HTML from onChange back in to keep it controlled. |
| onChange | (html: string) => void | None | Called with the document HTML after every edit. |
| title | string | None | Document title: the default download name and the title inside the .docx file. |
| filename | string | title | Download name, without the .docx extension. Falls back to title, then "document". |
| readOnly | boolean | false | Show the document without editing. The formatting controls are hidden. |
| downloadable | boolean | true | Show the Download .docx button. Turn it off when the host provides its own download. |
| height | number | string | '40rem' | Height of the editor. The page scrolls inside it. |
| aria-label | string | 'Document' | Accessible name of the editing area. |
| className | string | '' | Additional CSS classes on the root element. |
Accessibility
DocEditor's writing area is a multi-line textbox with an accessible name, and its toolbar is a labelled group of buttons. Tab moves into the toolbar and through each control, and the Left and Right arrows also move between them. Toggle buttons such as Bold report their state with aria-pressed, and the toolbar never takes focus away from the text, so the selection is kept while you format. In read-only mode the writing area is not editable and the formatting controls are removed.
| Key | Function |
|---|---|
| Tab | Moves between the toolbar and the writing area. |
| ←+→ | In the toolbar, moves between controls. |
| Ctrl/Cmd+B | Bold. Italic is I, underline is U. |
| Ctrl/Cmd+Z | Undo. Add Shift to redo. |
| Tab+Shift+Tab | In a list item, indents or outdents it. |