# Modern Rich Text Editor

> Recipe - a modern rich text editing experience with RichTextEditor - a floating selection toolbar, the slash menu, mentions, Markdown shortcuts, block editing and collaboration.

Canonical: https://salmonui.dev/docs/editors/modern-rich-text-editor

A "modern" rich text editing experience means a floating
toolbar over the selection, a slash menu, mentions, Markdown shortcuts and
block editing. Salmon UI has one rich text editor, `RichTextEditor`, built
on a modern engine (ProseMirror) with server rendering; this recipe
configures it for that experience.

```tsx
import { RichTextEditor } from '@salmonui/rich-text';
import '@salmonui/rich-text/styles.css';

<RichTextEditor
  aria-label="Post"
  toolbar="floating"                   // no fixed toolbar: a toolbar over the selection
  slashMenu                            // '/' opens the block menu
  mentions={{ items: people }}         // '@' mentions through the contenteditable Mention
  placeholder="Write, or type / for blocks"
  value={html}
  onChange={setHtml}
/>
```

### Live demo: Inline rich text toolbar

Live demo: https://salmonui.dev/demos/editors/rich-text-editor-inline

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.

`Demo.tsx`:

```tsx
'use client';

import { RichTextEditor, type RichTextEmoji } from '@salmonui/rich-text';
import '@salmonui/rich-text/styles.css';
import { EventLog, useEventLog } from '../../components/demo-kit';

const initial =
  '<h3>Team update</h3>' +
  '<p>This editor has no fixed toolbar: <strong><em>select any text</em></strong> and the toolbar appears over the selection.</p>' +
  '<p>Read the <a href="https://example.com/changelog" target="_blank" rel="noopener noreferrer">changelog</a> for details. Plain text here waits for the format painter.</p>' +
  '<p>Type a colon and a word, like :rocket or :tada, for emoji.</p>';

// A short emoji list replaces the built-in lazy one (emojiList).
const EMOJI: readonly RichTextEmoji[] = [
  { emoji: '🚀', name: 'rocket', keywords: ['launch', 'ship'] },
  { emoji: '🎉', name: 'tada', keywords: ['party', 'celebrate'] },
  { emoji: '✅', name: 'check', keywords: ['done', 'yes'] },
  { emoji: '⚠️', name: 'warning', keywords: ['risk', 'careful'] },
  { emoji: '👀', name: 'eyes', keywords: ['look', 'review'] },
  { emoji: '🐟', name: 'fish', keywords: ['salmon'] },
];

export default function RichTextEditorInlineDemo() {
  const [log, push] = useEventLog();
  return (
    <div style={{ display: 'grid', gap: 12, maxWidth: 720 }}>
      <RichTextEditor
        aria-label="Team update"
        defaultValue={initial}
        toolbar="floating"
        quickToolbars={{
          text: ['bold', 'italic', 'underline', 'fontColor', '|', 'link', 'formatPainter', 'emoji', 'clearFormat'],
          link: ['openLink', 'editLink', 'removeLink'],
        }}
        emojiList={EMOJI}
        placeholder="Write an update"
        onBeforePopupOpen={(event) => push(`onBeforePopupOpen: ${event.popup}`)}
        onCommand={(event) => push(`onCommand: ${event.command}${event.args.length ? ` ${JSON.stringify(event.args)}` : ''}`)}
        onDialogClose={(event) => push(`onDialogClose: ${event.dialog}`)}
        style={{ minBlockSize: 220 }}
      />
      <EventLog entries={log} />
    </div>
  );
}
```

What the Modern editor brings and where it lives:

| Modern RTE | Salmon UI |
| --- | --- |
| Minimal chrome, inline toolbar on selection | `toolbar="floating"`; or keep a fixed `toolbar` and add the `text` quick toolbar |
| Slash commands | `slashMenu` (built-in ids or custom `{ id, label, onSelect }` entries) |
| Mentions | `mentions` (`@salmonui/dropdowns/mention` on the editor's target) |
| Markdown shortcuts | Built in: `# `, `- `, `1. `, `[] `, `> `, three backticks |
| Block-based editing, drag handles | `BlockEditor` (block JSON value, handles, block menus) |
| Real-time collaboration | `@salmonui/rich-text/collab` with `extensions` |
| Extensible core | The `extensions` API (see [Headless editor](https://salmonui.dev/docs/editors/headless-editor)) |

When the content is a list of blocks rather than one HTML string (notes,
documents, pages), use [`BlockEditor`](https://salmonui.dev/docs/editors/block-editor) instead:
it shares the engine, the paste cleanup, the sanitizer and the extensions.
