RichTextEditor
Contenteditable HTML editor with configurable toolbar, placeholder, and HTML output.
import { RichTextEditor } from "phoundry-ui";Full Toolbar
Loading interactive example…
View source
<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
<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
<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
| Name | Type | Default | Description |
|---|---|---|---|
valuerequired | string | — | HTML content string. |
onchangerequired | (html: string) => void | — | Called when content changes. |
placeholder | string | 'Start writing…' | Placeholder text when empty. |
toolbar | ToolbarAction[] | [
'bold',
'italic',
'underline',
'strikethrough',
'code',
'link',
'heading',
'bulletList',
'numberedList',
'blockquote',
'horizontalRule',
'clearFormatting'
] | Which toolbar buttons to show. Defaults to all actions. |
disabled | boolean | false | Disable editing. |
minHeight | string | '120px' | Minimum editor height. |
maxHeight | string | '400px' | Maximum editor height before scrolling. |
class | string | '' | 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
valueis 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
maxHeightto constrain tall content - the editor scrolls internally. - The editor uses
contenteditable- no external dependencies required. - Toolbar shortcut keys:
⌘/Ctrl+B/I/Ufor bold/italic/underline,⌘/Ctrl+Kfor links,Tabinserts two spaces (does not move focus). - The
headingaction maps to anh3viaformatBlock- 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.