Rich Text Editor
- Value Format
- Read-Only
- Automatic Height Adjustment
- Theme Variants
- Toolbar Actions
- Related Components
Note
|
Commercial feature
A commercial Vaadin subscription is required to use Rich Text Editor in your project. |
Rich Text Editor is an input field for entering rich text. It allows you to format and style your text using boldface, italics, headings, lists, images, links, etc.
Value Format
Rich Text Editor supports the HTML format and the Quill Delta format for reading and setting its value.
HTML format details
Rich Text Editor supports values in the HTML format, with the following restrictions:
-
Only a subset of HTML tags are supported, which are listed in the table below.
-
Block elements, such as paragraphs, lists, or block quotes, can’t be nested.
-
Unsupported tags, such as
<b>
, are replaced with an equivalent supported tag, such as<strong>
, or with a paragraph (<p>
).
Feature | Tags |
---|---|
Paragraphs and line breaks |
|
Headings |
|
Bold, italic, underlined and strike-through text |
|
Links |
|
Text alignment via the |
|
Ordered, unordered lists, and list items |
|
Block quotes |
|
Pre-formatted text |
|
Images, using either a web URL or a Base64-encoded data URL |
|
The following snippet contains an HTML document that is supported by the component, and demonstrates the usage of several tags. Try pasting the snippet into the HTML Value
text area in the example below and see how the editor updates. Then try modifying the value, either by using the editor’s features, or by changing the HTML value directly.
Source code
HTML
<h2>High quality rich text editor for the web</h2>
<p>Rich text editor handles the following formatting:</p>
<ul>
<li><strong>Bold</strong></li>
<li><em>Italic</em></li>
<li><u>Underline</u></li>
<li><s>Strike-through</s></li>
</ul><h3>Blockquotes</h3>
<blockquote>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.
</blockquote><h3>Code blocks</h3>
<pre spellcheck='false'><body>
<vaadin-rich-text-editor></vaadin-rich-text-editor>
</body>
</pre>
Delta format details
The JSON-based Delta format consists of an array of operations to apply to a document. Rich Text Editor specifically only uses insert operations, each operation sequentially adding content to the document. Operations can have attributes, such as whether to render a piece of content with a specific text style, or as a link. For the full specification of the format, see the Quill Delta GitHub repository.
The following snippet contains a Delta document that demonstrates some of the format’s features.
Try pasting the snippet into the Delta Value
text area in the example below and see how the editor updates.
Then try modifying the value, either by using the editor’s features, or by changing the Delta value directly.
Source code
JSON
[
{"insert": "High quality rich text editor for the web\n", "attributes": {"header": 2}},
{"insert": "Rich text editor handles the following formatting:\n"},
{"insert": "Bold\n","attributes": { "bold": true, "list": "bullet" }},
{"insert": "Italic\n", "attributes": { "italic": true, "list": "bullet" }},
{"insert": "Underline\n", "attributes": { "underline": true, "list": "bullet" }},
{"insert": "Strike-through\n", "attributes": { "strike": true, "list": "bullet" }},
{"insert": "Blockquotes\n", "attributes": { "header": 3 }},
{"insert": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", "attributes": { "blockquote": true }},
{"insert": "Code blocks\n", "attributes": { "header": 3 }},
{"insert": "<vaadin-rich-text-editor></vaadin-rich-text-editor>\n", "attributes": { "code-block": true }}
]
For the Flow component, to read, write, or bind the component’s value with Binder
, use:
-
RichTextEditor.asDelta()
for the Delta format -
RichTextEditor.asHtml()
for the HTML format
For the web component, to read or write the value in the Delta format, use the value
property.
To read or write the value in the HTML format, use the htmlValue
property and the dangerouslySetHtmlValue
method.
Note
|
HTML sanitization
To prevent injecting malicious content, be sure to sanitize HTML strings before passing them to the web component using dangerouslySetHtmlValue . An example of this would be using a library such as dompurify.
|
Automatic Height Adjustment
Theme Variants
Toolbar Actions
History
Button | Title | Description |
---|---|---|
Undo | Reverses the previous action | |
Redo | Restores actions undone by |
Emphasis
Button | Title | Description |
---|---|---|
Bold | Boldens text | |
Italic | Italicizes text | |
Underline | Underlines text | |
Strikethrough | Strikes through text |
Headings
Three different headings are available in Rich Text Editor: H1, H2 ,and H3. Use them to signify structure (and importance).
Button | Title | Description |
---|---|---|
H1 | Heading level 1 | |
H2 | Heading level 2 | |
H3 | Heading level 3 |
Subscript and Superscript
Button | Title | Description |
---|---|---|
Subscript | Subscript text is positioned below the normal baseline and with smaller font size | |
Superscript | Superscript text is positioned above the normal baseline and with smaller font size |
List
Button | Title | Description |
---|---|---|
Ordered list |
| |
Unordered list |
|
Alignment
Button | Title | Description |
---|---|---|
Left align | Left-aligns text (default) | |
Center align | Center-aligns text | |
Right align | Right-aligns text |