Rich Text Editor
A compact formatted-text field for comments, replies and email bodies: bold, links, lists, quotes and code, a one-tab-stop toolbar, and a Markdown value.
c2-rich-text-editor is a form field for a few paragraphs of formatted text: a comment, a reply, an email body, a product description. It offers bold, italic, underline, strikethrough, inline code, links, bulleted and numbered lists, quotes and code blocks, and nothing more. For long documents with headings, tables, colours and images, use c2-page-editor.
formatspicks the buttons, their order and their groups ("bold italic | link | bullet ordered"). It is also what the keyboard shortcuts, the Markdown typed as you go (-,1.,>,**bold**) and paste may produce: a pasted heading becomes a line, pasted colours are dropped, and styles pasted from Google Docs or Word become the formats they show.toolbar-positionputs the toolbar at thetop, at thebottomnext to the app’s own buttons (a composer),floatingover selected text, ornone. Buttons that do not fit move into a “More” menu.- Keyboard: the toolbar is one tab stop (arrow keys move inside it, Alt+F10 jumps to it from the text, Escape goes back). Tab leaves the field, except in a list or a code block, where it indents; Escape there gives Tab back. ⌘/Ctrl+Enter fires
submit, which also submits an enclosing form. - Value: GitHub-flavoured Markdown,
''when the field is empty.toHTML()gives clean HTML for an email body. - Mentions and tags are the app’s: list the characters in
triggers, draw a picker on thetriggerevent, and finish withcompleteTrigger(text, { href }).
The element is a form control (name, required, maxlength with a counter, reset, disabled fieldsets) and takes its label, hint and error from an enclosing c2-form-field.
Import
import '@c2n/components/rich-text-editor'Usage
When to use which editor
| Need | Use |
|---|---|
| Plain text, no formatting | c2-textarea |
| A comment, reply, email body or short description | c2-rich-text-editor |
| A long document with headings, tables, colours, images | c2-page-editor |
| A chat message with attachments and a send button | c2-chat-input |