RichTextEditor

RichTextEditor is a rich text editor built on Tiptap and ProseMirror, with a themed toolbar that follows the WAI-ARIA toolbar pattern, inline link editing, HTML or JSON values and a character limit. It works with every kind of Angular form.

import { RichTextEditor } from '@exhaustive-ui/core/richtexteditor';

RichTextEditor is built on Tiptap and ProseMirror. Install the four open source Tiptap packages it uses, all MIT licensed; no Tiptap account, key or paid extension is needed. They are optional peer dependencies of ExhaustiveUI, so only the applications that use RichTextEditor install them. Tiptap is loaded in the browser only, on first use: during server-side rendering the component renders an empty placeholder.

npm install @tiptap/core @tiptap/pm @tiptap/starter-kit @tiptap/extension-text-align

ExhaustiveUI has two rich text editors. Editor wraps Quill and stays available unchanged for the applications that use it. RichTextEditor is built on Tiptap and ProseMirror and adds what Editor does not have: a toolbar that follows the WAI-ARIA toolbar pattern, with a single tab stop and the arrow keys, links edited in an inline panel that checks the URL, a value in HTML or in Tiptap JSON, a character limit with a count, and Tiptap extensions for your own content. Prefer RichTextEditor for new forms. Both values are HTML, but Quill and Tiptap do not write the same markup, lists for example, so check the stored content before moving an existing field from one to the other.

RichTextEditor is bound with ngModel and its value is an HTML string, or null when the editor is empty. The usual shortcuts work: Ctrl+B for bold, Ctrl+I for italic, Ctrl+K for a link, and Markdown shortcuts such as # for a heading or - for a list. Label the editable area with ariaLabelledBy or ariaLabel.

The toolbar input lists the buttons in order, and '|' separates two groups. The buttons are bold, italic, underline, strike, code, heading1, heading2, heading3, bulletList, orderedList, blockquote, codeBlock, link, alignLeft, alignCenter, alignRight, alignJustify, undo, redo and clear; textAlign adds the four alignments. An empty array hides the toolbar, the shortcuts keep working.

With format="json" the value is the JSON document of Tiptap instead of HTML. It is easier to store, to validate and to render on another platform, and it keeps every attribute of the content. The onTextChange event gives the HTML, the plain text and the JSON whatever the format.

{
  "type": "doc",
  "content": [
    {
      "type": "paragraph",
      "content": [
        {
          "type": "text",
          "marks": [
            {
              "type": "bold"
            }
          ],
          "text": "Before the release"
        }
      ]
    },
    {
      "type": "orderedList",
      "attrs": {
        "start": 1
      },
      "content": [
        {
          "type": "listItem",
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "type": "text",
                  "text": "Run the tests"
                }
              ]
            }
          ]
        },
        {
          "type": "listItem",
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "type": "text",
                  "text": "Update the changelog"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

maxLength limits the number of characters of the text, the formatting is not counted. Typing stops at the limit and a longer paste is cut, while a longer value written by the form is kept. showCount displays the count under the editor, linked to the editable area with aria-describedby, and the limit is announced to screen readers once reached. minHeight and maxHeight size the editable area.

When readonly is present, the content can be read, selected and copied but not changed. The toolbar is hidden and the editable area stays focusable for screen readers.

The toolbar template replaces the whole toolbar. It receives the Tiptap editor, undefined while Tiptap loads, an isActive function, the disabled state and openLink to open the link panel. Use the Tiptap commands, such as editor.chain().focus().toggleBold().run(). A custom toolbar takes care of its own keyboard support.

extensions adds Tiptap extensions to the StarterKit, the text alignment and the link support that the component already includes: your own nodes, marks and shortcuts, or any of the open source Tiptap extensions. The onInit event gives the Tiptap editor once it is created, to run commands from your own buttons. This example adds a highlight mark, toggled with Ctrl+Shift+H or the button.

When disabled is present, the editor and its toolbar cannot be focused or changed.

The invalid state is applied with the invalid property, which also sets aria-invalid on the editable area.

The value is null while the editor is empty, so required works as on the other fields. The control is marked as touched when the editable area loses the focus.

RichTextEditor can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.

RichTextEditor can also be used with Angular Signal Forms. The [formField] directive binds the component to a field holding the HTML, null when empty, so required works. To limit the length, use the maxLength input of the component, which counts the characters of the text, rather than the maxLength validator, which would count the HTML tags.

Screen Reader

The editable area has the textbox role with aria-multiline, and is named with ariaLabelledBy or ariaLabel; ariaDescribedBy links a hint or an error message. It also reports aria-invalid, aria-required, aria-readonly, aria-disabled and the placeholder with aria-placeholder. The toolbar follows the WAI-ARIA toolbar pattern: it has the toolbar role, a label and aria-controls, and only one button is in the tab order. Every button has a label, its shortcut in aria-keyshortcuts, and the formatting buttons tell whether they apply to the selection with aria-pressed. A button that cannot apply, such as undo with nothing to undo, has aria-disabled. The link panel is a labelled dialog whose field has a visible label and an error message linked with aria-describedby. When showCount is set, the count describes the editable area and reaching maxLength is announced. Every text can be replaced through labels.

<label id="body-label">Message</label>
<p-rich-text-editor ariaLabelledBy="body-label" ariaDescribedBy="body-hint" />
<small id="body-hint">Markdown shortcuts are supported.</small>

Toolbar Keyboard Support

KeyFunction
tabMoves the focus to the last focused button of the toolbar, then to the editable area.
right arrow / left arrowMoves the focus to the next or previous button, wrapping around. Reversed in right-to-left.
home / endMoves the focus to the first or last button.
enter / spaceRuns the focused button, the focus stays on it.
escapeMoves the focus back to the editable area.

Editable Area Keyboard Support

KeyFunction
alt + F10Moves the focus to the toolbar.
ctrl / cmd + b, i, uToggles bold, italic and underline.
ctrl / cmd + shift + s, ctrl / cmd + eToggles strikethrough and inline code.
ctrl / cmd + alt + 1 to 3Toggles a heading of level 1 to 3.
ctrl / cmd + shift + 8, 7, bToggles a bullet list, a numbered list and a quote.
ctrl / cmd + alt + cToggles a code block.
ctrl / cmd + kOpens the link panel when the toolbar has a link button.
ctrl / cmd + shift + l, e, r, jAligns the block left, center, right or justified.
ctrl / cmd + z, ctrl / cmd + shift + zUndoes and redoes.
tab / shift + tabIn a list, indents or outdents the item. Elsewhere, moves the focus out of the editor.

Link Panel Keyboard Support

KeyFunction
enterApplies the URL typed in the field.
escapeCloses the panel and moves the focus back to the editable area.