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.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | Markdown. '' when the field is empty. |
name | string | — | Name of the field in form data. |
label | string | — | Accessible name when the field is not inside a c2-form-field and has no aria-label. |
aria-label | string | null | null | Accessible name of the text, when there is no visible label to point at. Wins over an enclosing field's label. |
placeholder | string | — | Shown while the field is empty. |
formats | string | — | Space-separated formats the writer may use, in toolbar order, | starting a new group: bold italic underline strike code link bullet ordered quote code-block. Shortcuts, typed Markdown and paste produce only these. Empty
allows all. |
toolbar-position | RichTextToolbarPosition | top | Where the toolbar sits: top, bottom (in the footer, after footer-start), floating (over selected text; at the bottom on touch screens) or none. |
triggers | string | — | Space-separated characters that start a trigger when typed at the start of a word, e.g. "@ #". |
disabled | boolean | false | Not focusable, not editable and left out of the form data; the toolbar is inert. A disabled <fieldset> does the same. |
readonly | boolean | false | Selectable and focusable, without a toolbar; the value is still submitted. |
required | boolean | false | The field is invalid (valueMissing) while its text is empty or only whitespace. |
maxlength | number | -1 | Most characters of text (not Markdown) the field accepts: past it, a counter turns red and the field is invalid. -1 for no limit. |
Slots
| Name | Description |
|---|---|
toolbar-end | The app's own tools at the end of the toolbar (attach, mention, emoji). Each is a tab stop of its own. |
footer-start | Content at the start of the footer, such as a Send button. With toolbar-position="bottom" the toolbar follows it. |
footer-end | Content at the end of the footer, after the character counter, such as Cancel and Comment buttons. |
Events
| Name | Type | Description |
|---|---|---|
input | Event | Fired on each edit, after value is updated. |
format-change | CustomEvent<RichTextFormat> | Fired when the block or the formatting at the selection changes. Does not bubble. |
trigger | CustomEvent<RichTextTriggerDetail> | A character listed in triggers was typed at the start of a word, the word after it changed, or it ended (active: false). Does not bubble. |
change | Event | Fired when the field loses focus after its value changed. |
submit | Event | ⌘/Ctrl+Enter was pressed. Cancelable: unless it is cancelled, an enclosing form is submitted. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
container | The box around the toolbar, the text and the footer. |
toolbar | The formatting toolbar region: its buttons, then the toolbar-end slot, which projects the app's own tools after them (it has no fallback content). |
content | The editable text. |
footer | The row under the text: the footer-start slot, then the toolbar when it sits at the bottom, the counter, and the footer-end slot. Both slots project assigned content only, without fallback; the row is hidden while it has nothing to show. |
link-popover | The popover that edits a link. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-rich-text-editor__container--border | border | 1px solid #bcbcc6 | |
--c2-rich-text-editor__container--border-radius | border-radius | 6px | |
--c2-rich-text-editor__container--background | color | #ffffff | |
--c2-rich-text-editor__container--color | color | #18181b | |
--c2-rich-text-editor__container__hover--border | border | 1px solid #a1a1aa | |
--c2-rich-text-editor__container__focus--border | border | 1px solid #476ef9 | |
--c2-rich-text-editor__container__focus--box-shadow | box-shadow | none | A focus ring around the whole field, e.g. 0 0 0 3px rgba(2, 101, 220, 0.15). |
--c2-rich-text-editor__container__error--border | border | 1px solid #dc2626 | While invalid: over maxlength, or an enclosing c2-form-field shows an error. |
--c2-rich-text-editor__container__read-only--background | color | #fafafa | |
--c2-rich-text-editor__container__disabled--opacity | opacity | 0.38 | |
--c2-rich-text-editor__toolbar--padding | padding | 6px | |
--c2-rich-text-editor__toolbar--gap | pixel | 2px | |
--c2-rich-text-editor__toolbar--border | border | 1px solid #e4e4e7 | The line between the toolbar and the text (above it when the toolbar is at the bottom). |
--c2-rich-text-editor__tool--size | pixel | 32px | Width and height of a toolbar button; at least 44px on touch screens. |
--c2-rich-text-editor__tool--border-radius | border-radius | 4px | |
--c2-rich-text-editor__tool--color | color | #52525b | |
--c2-rich-text-editor__tool__hover--background | color | #f4f4f5 | |
--c2-rich-text-editor__tool__pressed--background | color | #edf1fe | A format the selection carries. |
--c2-rich-text-editor__tool__pressed--color | color | #0265dc | |
--c2-rich-text-editor__tool__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-rich-text-editor__separator--color | color | #e4e4e7 | |
--c2-rich-text-editor__content--padding | padding | 10px 12px | |
--c2-rich-text-editor__content--min-height | pixel | 80px | The text grows from this height… |
--c2-rich-text-editor__content--max-height | pixel | none | …to this one, then scrolls. |
--c2-rich-text-editor__content--font-family | font-family | inherit | |
--c2-rich-text-editor__content--font-size | font-size | 14px | |
--c2-rich-text-editor__content--line-height | pixel | 22px | |
--c2-rich-text-editor__block--margin-top | pixel | 6px | Space between paragraphs, lists, quotes and code blocks. |
--c2-rich-text-editor__placeholder--color | color | #71717a | |
--c2-rich-text-editor__selection--background | color | rgba(2, 101, 220, 0.18) | |
--c2-rich-text-editor__link--color | color | #0265dc | |
--c2-rich-text-editor__quote--border-left | border | 3px solid #d4d4d8 | |
--c2-rich-text-editor__quote--color | color | #52525b | |
--c2-rich-text-editor__item--indent | pixel | 22px | Indentation of one list level, which is also the width of the marker column. |
--c2-rich-text-editor__code--font-family | font-family | ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace | |
--c2-rich-text-editor__inline-code--background | color | rgba(135, 131, 120, 0.15) | |
--c2-rich-text-editor__inline-code--border-radius | border-radius | 4px | |
--c2-rich-text-editor__code-block--background | color | #f4f4f5 | |
--c2-rich-text-editor__code-block--border-radius | border-radius | 4px | |
--c2-rich-text-editor__footer--padding | padding | 8px 10px 10px 12px | |
--c2-rich-text-editor__footer--gap | pixel | 8px | |
--c2-rich-text-editor__counter--font-size | font-size | 12px | |
--c2-rich-text-editor__counter--color | color | #71717a | |
--c2-rich-text-editor__counter__error--color | color | #dc2626 | |
--c2-rich-text-editor__popover--background | color | #ffffff | The link popover and the floating toolbar. |
--c2-rich-text-editor__popover--border | border | 1px solid #e4e4e7 | |
--c2-rich-text-editor__popover--border-radius | border-radius | 8px | |
--c2-rich-text-editor__popover--box-shadow | box-shadow | 0 8px 24px rgba(24, 24, 27, 0.12), 0 2px 6px rgba(24, 24, 27, 0.06) | |
--c2-rich-text-editor__link-input--border | border | 1px solid #bcbcc6 | |
--c2-rich-text-editor__button--background | color | #0265dc | The link popover's Save button. |
--c2-rich-text-editor__button--color | color | #ffffff | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under rich-text-editor, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
formatting | Formatting | — |
moreFormatting | More formatting | — |
bold | Bold | — |
italic | Italic | — |
underline | Underline | — |
strike | Strikethrough | — |
code | Inline code | — |
link | Link | — |
bullet | Bulleted list | — |
ordered | Numbered list | — |
quote | Quote | — |
codeBlock | Code block | — |
withShortcut | {0} ({1}) | {0} name {1} keys |
linkAddress | Link address | — |
linkSave | Save | — |
linkRemove | Remove link | — |
counter | {0} / {1} | {0} count {1} max |
valueMissing | Please fill in this field. | — |
tooLong | Use {0} characters or fewer. | {0} max |