Skip to content

RichTextEditor

Contenteditable HTML editor with configurable toolbar, placeholder, and HTML output.

import { RichTextEditor } from "phoundry-ui";

Full Toolbar

Loading interactive example…

View source
full-toolbar.svelte
<script lang="ts">
import { RichTextEditor } from "phoundry-ui";
let fullContent = $state("<p>Start editing here...</p>");
const fullToolbar = [
"bold",
"italic",
"underline",
"strikethrough",
"code",
"heading",
"bulletList",
"numberedList",
"blockquote",
"link",
"horizontalRule",
"clearFormatting",
] as const;
</script>
<RichTextEditor
value={fullContent}
onchange={(html: string) => {
fullContent = html;
}}
toolbar={[...fullToolbar]}
/>

Minimal Toolbar

Loading interactive example…

View source
minimal-toolbar.svelte
<script lang="ts">
import { RichTextEditor } from "phoundry-ui";
let minimalContent = $state("");
const minimalToolbar = ["bold", "italic", "link"] as const;
</script>
<RichTextEditor
value={minimalContent}
onchange={(html: string) => {
minimalContent = html;
}}
toolbar={[...minimalToolbar]}
placeholder="Write a comment..."
minHeight="80px"
/>

Disabled

Loading interactive example…

View source
disabled.svelte
<script lang="ts">
import { RichTextEditor } from "phoundry-ui";
let disabledContent = $state("<p>Read-only body</p>");
</script>
<p class="mb-2 text-xs text-txt-secondary">
Toolbar actions no-op; the surface is not editable.
</p>
<RichTextEditor
value={disabledContent}
onchange={(html: string) => (disabledContent = html)}
disabled
minHeight="72px"
/>

API

From phoundry-ui@0.4.21

NameTypeDefaultDescription
valuerequiredstring—HTML content string.
onchangerequired(html: string) => void—Called when content changes.
placeholderstring'Start writing…'Placeholder text when empty.
toolbarToolbarAction[][ 'bold', 'italic', 'underline', 'strikethrough', 'code', 'link', 'heading', 'bulletList', 'numberedList', 'blockquote', 'horizontalRule', 'clearFormatting' ]Which toolbar buttons to show. Defaults to all actions.
disabledbooleanfalseDisable editing.
minHeightstring'120px'Minimum editor height.
maxHeightstring'400px'Maximum editor height before scrolling.
classstring''Additional CSS classes.

ToolbarAction Values

From phoundry-ui@0.4.21

  • "bold" — Bold text formatting.
  • "italic" — Italic text formatting.
  • "underline" — Underline text.
  • "strikethrough" — Strikethrough text.
  • "code" — Inline code formatting.
  • "link" — Insert or edit hyperlink.
  • "heading" — Toggle heading level.
  • "bulletList" — Unordered list.
  • "numberedList" — Ordered list.
  • "blockquote" — Block quote formatting.
  • "horizontalRule" — Insert horizontal rule.
  • "clearFormatting" — Remove all formatting from selection.

Usage tips

  • The value is raw HTML - sanitize it before persisting or rendering elsewhere to prevent XSS.
  • Use a minimal toolbar (['bold', 'italic', 'link']) for comment fields and short-form inputs.
  • Set maxHeight to constrain tall content - the editor scrolls internally.
  • The editor uses contenteditable - no external dependencies required.
  • Toolbar shortcut keys: ⌘/Ctrl+B/I/U for bold/italic/underline, ⌘/Ctrl+K for links, Tab inserts two spaces (does not move focus).
  • The heading action maps to an h3 via formatBlock - browser support for formatting commands varies slightly.

CSS styling

.ph-rich-text-editor is the stable identification hook for RichTextEditor. Part selectors and --_ph-* properties are internal. Component CSS is scoped and unlayered; Consumer classes remain additive and utility overrides may lose precedence.

Toolbar and contenteditable-body styles are separate. Styles for generated rich-text markup remain scoped to the editor body.

Keep the shared component stylesheet and a named Theme imported. Decorative motion respects reduced-motion preferences.

Documentation is licensed under CC BY 4.0. Phoundry names and marks remain reserved.