Team update
This editor has no fixed toolbar: select any text and the toolbar appears over the selection.
Read the changelog for details. Plain text here waits for the format painter.
Type a colon and a word, like :rocket or :tada, for emoji.
Components
RichTextEditor from @salmonui/rich-text - an HTML editor on ProseMirror that server-renders its value, with toolbars, quick toolbars, tables, media uploads through callbacks, find and replace, source view, mentions and a streaming AI hook.
RichTextEditor edits an HTML value. It lives in
@salmonui/rich-text, the one Salmon UI package that may use ProseMirror;
every other package except @salmonui/pdf-viewer has no runtime
dependencies.
import { RichTextEditor } from '@salmonui/rich-text';
import '@salmonui/rich-text/styles.css';
<RichTextEditor
aria-label="Body"
defaultValue="<p>Hello</p>"
onChange={(html) => save(html)}
onUpload={async (file) => ({ src: await uploadToServer(file) })}
/>;
The stylesheet carries the button, menu and mention rules the toolbar and
the mention list render, so it is the only stylesheet besides
@salmonui/core/styles.css (the theme, once per app).
The server renders the toolbar shell and the sanitized HTML of value
inside the content element (role="textbox", aria-multiline). After
hydration the editing engine loads with one dynamic import() and mounts
on that same element, so the markup matches and there is no hydration
warning. The root entry never loads ProseMirror on the server;
loadRichTextEngine() preloads it on the client if you want the first
keystroke to be instant. To show stored HTML read-only, use
RichTextContent.
value / defaultValue hold an HTML string; onChange(html) fires once
per batch of transactions, changeDelay (ms) widens the batch, and onBlur(html) gives a
change-on-blur timing. A controlled value goes into the engine, never through
React re-rendering the content. Every value in and every HTML out passes
the always-on sanitizer (see
HTML sanitizer and paste cleanup).
Through actionsRef:
| Member | Does |
|---|---|
getHtml({ xhtml? }) |
The HTML value; xhtml: true self-closes void elements |
getText() |
Plain text, blocks joined by new lines |
commands.bold(), commands.insertTable({ rows, cols }), ... |
Typed commands; each fires onBeforeCommand (cancellable) and onCommand |
run(id, ...args) |
A command or toolbar action by id |
getSelection() / setSelection(anchor, head) / focus() |
Selection API |
clearHistory() |
Empties undo and redo |
openDialog(id) / closeDialog() |
Built-in dialogs |
insertFiles(files) |
Inserts images or media through onUpload |
There is no refreshUI: toolbar state follows the editor state.
toolbar lists built-in item ids, '|' separators and custom items
({ id, label, icon, onClick, pressed, disabled }); a built-in id can be
written { id: 'bold', disabled: true }. Defaults are in
RICH_TEXT_DEFAULT_TOOLBAR. Items are Button, ToggleButton and
MenuButton from @salmonui/buttons, inside an APG toolbar: one tab stop,
arrow keys move between items, Alt+F10 in the editor focuses the toolbar and
Escape returns.
toolbarOverflow: 'menu' (default) moves
what does not fit into a "More" menu, 'scroll' scrolls, 'wrap' uses
several rows.toolbarPosition: 'top' | 'bottom', stickyToolbar.toolbar="floating" shows the toolbar only over a text selection;
toolbar={false} hides it.quickToolbars: item lists per context (link, image, table, text,
audio, video; false hides one), shown in a popover next to the
selected link, image, table or media. The defaults are
RICH_TEXT_DEFAULT_QUICK_TOOLBARS. The text quick toolbar appears over
a text selection only when you give it a list (or with
toolbar="floating"). An audio or video node selected with the arrow
keys shows the audio or video list.<RichTextEditor
quickToolbars={{
text: ['bold', 'italic'], // a selection toolbar next to the fixed one
video: ['alignments', 'removeNode'],
link: false, // no link popover
}}
/>
RichTextEditor in inline mode - toolbar="floating" shows a toolbar over the selection with links, the format painter and the emoji picker; the link quick toolbar opens, edits and removes links.
This editor has no fixed toolbar: select any text and the toolbar appears over the selection.
Read the changelog for details. Plain text here waits for the format painter.
Type a colon and a word, like :rocket or :tada, for emoji.
Marks: bold, italic, underline, strikethrough, subscript, superscript,
inline code, font family, font size, text color and background color, plus
uppercase and lowercase commands (fontFamilies, fontSizes,
colors set the pickers). Blocks: paragraph and heading formats,
alignment, bulleted, numbered and checklists with list styles, indent and
outdent, line height, blockquote, horizontal rule and clear format.
The format painter copies marks and the block format: a click applies once,
a double click keeps applying, Escape ends. Markdown-style input
rules (# , - , 1. , > , [] , ```` `) work as you type.
rel="noopener noreferrer"), and a quick toolbar to open, edit or remove.
Unsafe URLs are refused.onUpload(file) => Promise<{ src, alt? }>. A pasted or dropped image shows
a pending placeholder until the promise settles; a rejection removes it
and calls onUploadError. Without onUpload, imageInsert is 'blob'
(default) or 'base64'.onUpload, rendered with native controls;
embeds (<iframe>) only from hosts in embedHosts.codeLanguages picker; highlight(code, language)
decorates them, no highlighter is bundled.onBrowseFiles(kind) opens your own file browser from the image and media
dialogs.pasteCleanup normalizes Word and Google Docs HTML to the editor
vocabulary, keeps it, pastes plain text, or prompts. There is no
built-in Word or PDF service: onImport(file) => Promise<string>
receives the file from the import item and returns HTML that is sanitized
and inserted, and getHtml() gives the HTML to export. A server converts
Word files (for example with mammoth, LibreOffice or a document server) and
renders PDF from that HTML; built-in DOCX interop is not included.
RichTextEditor inserts - audio and video from a URL or an upload, allow-listed embeds, a code block with an application highlight hook, an application file browser, file import, HTML export and a streaming, provider-agnostic AI assistant.
Insert media from the Audio and Video items, browse the demo assets from the Image or Audio dialog, import a file, or ask the assistant.
const answer = 42;
// a comment
export function greet(name: string) {
return `Hello ${name}`;
}'findReplace' toolbar item.'sourceCode' switches to an HTML textarea; switching back sanitizes it.showCount shows the character count in the status bar; maxLength is
enforced by a transaction filter, so typing and pasting past it is
refused while deletions still apply; the count is announced politely at
thresholds only.resizable, controlled fullscreen / onFullscreenChange, and
'print', which prints the content only./ at the start of a word opens the block menu (slashMenu: true, or
your own items with onSelect).'emoji' item and : open the emoji picker (search, arrows, Enter);
the built-in list is a lazy chunk, emojiList replaces it.mentions={{ trigger: '@', items | onSearch, renderItem }} attaches
Mention to the editor and inserts mention
nodes.aiAssistant={{ onRequest({ prompt, selectionHtml, signal }) }} may return
a string or an AsyncIterable<string>. The answer streams into a pending
insert that the user accepts or discards. Model output is inserted as
escaped text, never rendered as HTML. There is no built-in model or
provider. WebMCP tool registration is not built in:
register actionsRef commands yourself.
The default shortcuts are the common editor ones (Mod+B, Mod+I, Mod+U, Mod+Z,
Mod+Shift+Z, Mod+Y, Mod+K for a link, Mod+Shift+F for fullscreen, Mod+Shift+H for the source view, ...); keyBindings maps a key to a
command id, an action id, a function, or false to remove a default.
enterKey ('p', 'div', 'br') and shiftEnterKey choose
what Enter and Shift+Enter insert; tabKey: 'focus' (default) leaves Tab to
the page, 'indent' indents.
Transaction history with undoLimit and undoGroupDelay (ms between
typing groups); toolbar items 'undo', 'redo'.
name renders a hidden input with the HTML value, form reset restores
defaultValue, required blocks an empty submit, and invalid sets
aria-invalid. placeholder, readOnly and disabled.
Inside a Field the editor uses the Field error
display of the Inputs components: the field label names the editor
(aria-labelledby), the description and the visible error are in
aria-describedby, aria-errormessage points at the error, and the
Field's rules run on blur and when a submit reaches the empty required
editor. Pass the HTML to the Field as value (an empty editor reports
''):
import { Field } from '@salmonui/inputs/form';
import '@salmonui/inputs/form/styles.css';
<Field label="Article body" description="Shown on the front page" name="body" validation={{ required: true }} value={html}>
{() => <RichTextEditor name="body" required defaultValue="" onChange={setHtml} />}
</Field>
Events come in before/after pairs: onBeforeCommand / onCommand,
onToolbarItemClick, onBeforeDialogOpen / onDialogClose,
onBeforePopupOpen, onToolbarStateChange.
RichTextEditor driven from code and forms - typed commands, selection and history through actionsRef, Enter and Tab configuration, a custom key binding, readOnly and disabled, a disabled toolbar item, required form submit and reset, every before/after event, right to left and localized labels.
localeText (defaults in RICH_TEXT_EDITOR_DEFAULT_LOCALE_TEXT), inherited
dir (the toolbar mirrors, the content follows), className and style
on the root; set the size with CSS width and height. Colors
come from the theme seeds. There is no built-in persistence (see
Design notes).
extensions adds nodes, marks, commands, key bindings, input rules,
toolbar items and ProseMirror plugins (an async plugin factory is awaited
before the editor mounts); collaboration from @salmonui/rich-text/collab
is one. See Headless editor.
A floating toolbar, slash menu, mentions, Markdown shortcuts and block
editing are configuration of RichTextEditor, see
Modern Rich Text Editor.
contenteditable element whose
CSS is scoped under .salmon-rich-text, so the editor server-renders its
value and shares the page theme. Scope custom content CSS under the
editor's className.onImport for Word
import and send getHtml() to your own converter for
Word or PDF export.onBrowseFiles(kind) opens your own
browser (see the
File Manager).aiAssistant.onRequest calls your provider
and handles each prompt request.actionsRef.current.commands
as tools in application code, with your own confirmation step before a
tool runs.localStorage
on their own, because hidden persistence breaks server rendering
consistency. Store what onChange reports and pass it back as value or
defaultValue.refreshUI is not needed: toolbar state follows the editor state.@salmonui/rich-text lists every prop,
command, callback and type of RichTextEditor, RichTextContent,
BlockEditor and the engine; @salmonui/rich-text/collab
the collaboration helpers.
An HTML editor with the default toolbar, quick toolbars, tables, uploads through a callback, mentions, a character limit and the live HTML value.
Type / for blocks, @ to mention someone and : for emoji.
Select text for the quick toolbar
Paste from Word: the markup is cleaned
Area | Status |
|---|---|
Editor | Ready |
<h2>Release notes</h2><p>Type <strong>/</strong> for blocks, <strong>@</strong> to mention someone and <strong>:</strong> for emoji.</p><ul><li><p>Select text for the quick toolbar</p></li><li><p>Paste from Word: the markup is cleaned</p></li></ul><table><tbody><tr><th><p>Area</p></th><th><p>Status</p></th></tr><tr><td><p>Editor</p></td><td><p>Ready</p></td></tr></tbody></table>