Rich text editor
A field for notes, emails and briefs with headings, lists, links and @mentions, its value in markdown.
Shared with the hiring panel. Type @ to mention someone, / for commands.
Engine
The editor runs on Lexical, an optional peer of Satin Pro that only this entry imports. Install it next to@uisatin/pro: npm i lexical @lexical/rich-text @lexical/list @lexical/link @lexical/markdown @lexical/history @lexical/table. In an app's production build Lexical adds about 97 kB gzipped, and about 20 kB more for tables; the editor's own code is about 14 kB, and Radix Popover (about 22 kB, which Satin Free's popovers load too) places its bubble and link popover. None of the rest is in the Satin Free bundle, and @uisatin/pro itself doesn't export the editor, so only a page that imports @uisatin/pro/rich-text-editor loads it.
Other teams
A sales follow-up that mentions the account owner, a campaign brief with headings, a numbered list and a link, and a product description pasted from Google Docs. A paste from Google Docs, Word or a web page keeps bold, italic, lists and links; underline, highlight, subscript and superscript are dropped, since the markdown has no place for them (a Google Docs link arrives underlined and keeps only its link).
In a dialog
With maxLength a count of the text, not the markdown, shows in the status slot under the field. It isn't enforced. Escape closes the mention menu first, and only the next Escape closes the dialog.
Selection actions
Build the editor from its parts to add actions to the bubble over a selection: RichTextSelectionToolbar'sactions go after bold, italic, strikethrough and link, past a separator. Any Toolbar item works there, andeditorRef's insert, insertText and getSelectionRect act on the text. Here Comment keeps the selected words.
In a form
Inside a FormField the editor takes its label, description, error, required andname; a hidden input carries the markdown into the form's values. Publish with the field empty shows the error.
Installation
npm i @uisatin/ui @uisatin/proimport '@uisatin/ui/styles.css'
import '@uisatin/pro/styles.css'
import { RichTextEditor } from '@uisatin/pro/rich-text-editor'Part of Satin Pro, the licensed edition: @uisatin/pro on top of @uisatin/ui at the same version, its stylesheet after Free's. Satin Pro isn't on npm yet.
About 156.9 kB of JavaScript, minified and gzipped, on top of the @uisatin/uicomponents it uses (React aside).
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The RichTextEditor component (Satin Pro, @uisatin/pro/rich-text-editor) is a field with Textarea's look whose editable area is a role="textbox" with aria-multiline. It edits headings, lists, quotes, tables, links, bold, italic, strikethrough, inline code and mentions. It runs on Lexical, an optional peer that only this entry imports (npm i lexical @lexical/rich-text @lexical/list @lexical/link @lexical/markdown @lexical/history @lexical/table): about 97 kB gzipped in production, about 20 kB more with tables, plus about 14 kB of the editor's own, and Radix Popover for the bubble and the link popover, which Satin Free's popovers load too; none of the rest is in the Satin Free bundle. value is markdown (format="markdown") or Lexical's JSON (format="json"), controlled or not; a mention is written [@Tara Mendes](mention:tara-id), a table as GFM (| Area | Rating |, a | --- | --- | divider under its header row; Tab and Shift+Tab move between cells, and a table comes in through markdown, from a command or a value, not from a control), and onValueChange(value, { mentions }) lists them (richTextMentions(value, format) reads them from any value). The editor sends only edits, never on mount, and doesn't load back a value it sent itself. A paste keeps bold, italic, lists and links; underline and other marks it has no place for are dropped. With maxLength a CharacterCount of the text shows in the status slot. toolbar is the formatting toolbar inside the field (true, "minimal" or false), selectionToolbar the bubble over a pointer selection. editorRef has focus, insert(markdown), insertText, getValue and getSelectionRect. Inside a FormField it takes the label, the error, required and name. mentions ({ trigger, search }, Prompt bar's with an avatar) opens a menu on @ at a block's start or after a space; a pick goes in as a mention, one unit. commands opens on /; a pick takes "/query" out and calls the command's run({ insert, editor }), where insert puts markdown at the caret. Parts: RichTextEditorRoot (the engine and the value) holds RichTextEditorContent (the field) with RichTextToolbar inside it, and RichTextSelectionToolbar, whose actions add your own items to the bubble; a toolbar of your own takes RichTextBlockTypeMenu, RichTextFormatToggle, RichTextBlockToggle and RichTextLinkButton. For a Lexical setup of your own: RICH_TEXT_NODES, RICH_TEXT_TRANSFORMERS (with MENTION and TABLE), MentionNode and normalizeRichTextUrl.
| Prop | Type | Default |
|---|---|---|
value | string | — |
defaultValue | string | — |
onValueChange | (value: string, details: { mentions: RichTextMentionRef[] }) => void | — |
format | "markdown""json" | "markdown" |
label | ReactNode | — |
optional | boolean | false |
hint | ReactNode | — |
error | ReactNodeboolean | — |
placeholder | string | — |
status | ReactNode | — |
maxLength | number | — |
toolbar | boolean"minimal" | true |
selectionToolbar | boolean | true |
readOnly | boolean | false |
disabled | boolean | false |
required | boolean | false |
name | string | — |
autoFocus | boolean | false |
fieldClassName | string | — |
mentions | { trigger?: string; search: (query: string) => RichTextMention[] | Promise<RichTextMention[]> } | — |
commands | RichTextCommand[] | — |
RichTextCommand.run | ({ insert, editor }) => void | — |
editorRef | Ref<RichTextEditorHandle> | — |
RichTextEditorHandle.focus | () => void | — |
RichTextEditorHandle.insert | (markdown: string) => void | — |
RichTextEditorHandle.insertText | (text: string) => void | — |
RichTextEditorHandle.getValue | () => string | — |
RichTextEditorHandle.getSelectionRect | () => DOMRect | null | — |
RichTextEditorRoot.labelledBy / describedBy | string | — |
RichTextEditorRoot.invalid | boolean | false |
RichTextEditorContent.children | ReactNode | — |
RichTextToolbar.preset | "default""minimal" | "default" |
RichTextToolbar.children | ReactNode | — |
RichTextSelectionToolbar.children | ReactNode | — |
RichTextSelectionToolbar.actions | ReactNode | — |
RichTextFormatToggle.format | "bold""italic""strikethrough""code" | — |
RichTextBlockToggle.block | "bullet""number""quote" | — |
RichTextLinkButton / RichTextBlockTypeMenu | ToolbarTogglePropsToolbarButtonProps | — |
Accessibility
The editable area is a div with contenteditable, role="textbox" and aria-multiline, named by the label through aria-labelledby (a FormField's label too; with neither, aria-label or "Text editor", richTextEditor in SatinLabels). Clicking the label focuses it. The hint or the error and the count describe it (aria-describedby); an error sets aria-invalid, a required FormField aria-required. The placeholder is its aria-placeholder, and the visible one is hidden from screen readers. Headings, lists, quotes, tables and links are real elements, so a screen reader moves through them as on a page. A mention reads as its text, "@Tara Mendes". Read-only stays in the tab order with aria-readonly, and its text can be selected and copied; disabled leaves the tab order and is aria-disabled. The focus ring is drawn on the field while the editable area has focus. The formatting toolbar is Free's Toolbar (role="toolbar", "Formatting"), one tab stop before the text, its toggles with aria-pressed that follow the selection; the text has aria-keyshortcuts="Alt+F10" to reach it. The bubble over a selection is a toolbar too, out of the tab order, shown for pointer selections; ⌥F10 opens it from the keyboard when there is no fixed toolbar. With mentions or commands the editable area has aria-autocomplete="list"; while the menu lists rows it points at the listbox with aria-controls and at the highlighted option with aria-activedescendant, and focus stays in the text. A polite status region says how many suggestions there are, "No results", and which mention went in or out. An input method's text (Japanese, Chinese, Korean) never opens a menu, and its Enter confirms the composition, not a pick. The bubble and the link popover are popover layers, so inside a modal Dialog they take presses and focus and Escape closes them first; the bubble never takes focus on its own, the link popover moves it to its address field. They fade in; reduced motion turns that off. Known gap: inside a table, Tab moves between cells, listed on the Accessibility page.
| Key | Action |
|---|---|
| Tab | Moves focus to the toolbar, then the text, then out. In a table, moves to the next cell instead; ⇧Tab to the previous one. |
| ⌥F10 | In the text: moves to the toolbar's first item, or opens the selection bubble when there is no toolbar. |
| →or←orHomeorEnd | In a toolbar: ← and → move between its items, wrapping at the ends; Home and End go to the first and the last. |
| Esc | In the bubble or the link popover, or with the bubble up: closes it and goes back to the text with its selection; a Dialog around the editor stays open. In the formatting toolbar: goes back to the text, except inside a Dialog, where it closes the Dialog as Escape does on any control in one. |
| ⌘Bor⌘Ior⌘⇧Xor⌘E | Bold, italic, strikethrough, inline code on the selection or what is typed next. Ctrl for ⌘ off Apple. |
| ⌘⇧8or⌘⇧7 | A bullet or a numbered list. |
| ⌘K | Opens the link popover under the selection; Enter applies the address. |
| ⌘Zor⌘⇧Z | Undoes and redoes the last edits. |
| Enter | A new paragraph, or a new list item; on an empty list item, leaves the list. |
| ⇧Enter | A line break in the same paragraph. |
| @or/ | At a block's start or after a space: opens the mentions or the commands menu. |
| ↑or↓ | Menu open: moves the highlight, wrapping. |
| EnterorTab | Menu open: inserts the highlighted mention, or runs the highlighted command. |
| Esc | Menu open: closes it until the next trigger. With no menu open the editor doesn't take it, so a Dialog around it closes. |
| ⌫ | Right after a mention: removes all of it. |
Something wrong or missing on this page?
Report a problemSuggest an improvement