API REFERENCE · EDITING
<dj-rich-text>
A form-associated WYSIWYG editor built on Lexical.
The value is HTML by default. Formatting, headings, lists, links, and other content types come from plugins, through the same plugin API that third-party plugins use.
npm install @dojo-ng/rich-text
import "@dojo-ng/rich-text";
Plugins
- Bold, italic, underline, undo, and redo are the default plugin set,
defaultPlugins. - Setting
pluginsreplaces the defaults, so spread...defaultPluginsto keep them. - Lexical needs its node types when the editor is created, so changing
pluginslater rebuilds the editor, keeping its content. Setpluginsbeforevalue. formatselects another serializer that a plugin contributes, such as Markdown.
rich-text-autolinkAuto-link (URL/email) pluginrich-text-colorText/background color pluginrich-text-criticmarkupCriticMarkup tracked-changes pluginrich-text-embedMedia embed pluginrich-text-emojiEmoji picker + shortcode pluginrich-text-headingsHeadings/quote pluginrich-text-imageImage insert pluginrich-text-linksLink insert/edit/remove pluginrich-text-listsBulleted/numbered/checklist pluginrich-text-markdownMarkdown input/output pluginrich-text-mentionsMentions (@name) pluginrich-text-slashSlash-command menu pluginrich-text-tableTable plugin
The value
valuecan be read and written at any time. Writing it replaces the whole document, clears the selection and the undo history, and does not emitdj-change, like a native input'svalue.dj-changefires when the user edits the content.
Pasting
- Pasted HTML is cleaned against an allowlist by default. Scripts, styles, event handlers, inline styles, and unsafe
javascript:anddata:URLs are removed. Unknown tags are removed but their text is kept. - Set
sanitizePaste = falsefrom JavaScript to turn this off, or setpasteSanitizerto your own(html) => htmlfunction. The default is exported assanitizeHtml. - Plain-text pastes are not cleaned, since they contain no markup.
Light DOM
- The editable area renders in the light DOM, because Lexical's selection handling is not reliable inside a shadow root.
--dj-*theme tokens still apply.
Properties
| Property | Attribute | Type | Default |
|---|---|---|---|
valueThe document, serialized through the active format (HTML by default). Readable and writable at any time, not just at construction: assigning after the editor is built replaces the whole document, discarding the selection and undo history, and emits no dj-change — the same as setting a native input's value. |
value |
string |
"" |
name |
name reflected |
string |
None |
label |
label |
string |
None |
placeholder |
placeholder |
string |
"" |
disabled |
disabled reflected |
boolean |
false |
pluginsPlugin set. Set in JavaScript (rich data). The default set is used when this is empty. |
Property only | RichTextPlugin[] Plugins |
[] |
formatOutput format; selects which serializer the value getter/setter uses. "html" is built in. |
format reflected |
string |
"html" |
sanitizePasteSanitize pasted HTML against an allowlist (on by default). Set in JS to disable. |
Property only | boolean |
true |
pasteSanitizerCustom paste sanitizer (html) => html; defaults to the built-in allowlist sanitizeHtml. |
Property only | (html: string) => string |
None |
Events
dj-change
Methods
| Method | Description |
|---|---|
checkValidity(): boolean | |
focus(o: FocusOptions) | |
setHtml(htmlString: string) | Replace the document with the given HTML (regardless of the active format). |