Skip to main content

RichTextEditor

A small, dependency-free rich-text field (contentEditable + toolbar). Its HTML normalisation is a UX guard, not a security boundary — always sanitise on the server before storing or rendering the value.

Signature
Density
Viewport
Theme and light/dark are set in the top bar
Live demo
Open ↗

When to use​

A small, dependency-free rich-text field (contentEditable + toolbar).

Accessibility​

Always render a visible <label> (the label prop wires htmlFor/id for you). Errors set aria-invalid and are announced via aria-describedby. Required fields expose aria-required.

Install and import​

npx shadcn@latest add @prism/rich-text-editor
import { RichTextEditor } from '@/components/prism/RichTextEditor';

In a no-build prototype, read it from the bundle instead: const { RichTextEditor } = window.PrismDesignSystem_39d121;

Props​

PropTypeRequiredDescription
labelReact.ReactNode—
descriptionReact.ReactNode—Helper text under the label; linked via aria-describedby.
hintReact.ReactNode—A short note at the end of the label row (e.g. "Optional", "Shown to parents"), as TextField's hint; linked via aria-describedby.
errorMessageReact.ReactNode—Shown when isInvalid; announced and linked via aria-describedby.
isRequiredboolean—Blocks native submit while the editor has no text.
isInvalidboolean—
isDisabledboolean—
valuestring—Controlled value: HTML limited to b/strong, i/em, u, ul, ol, li, p, br and a[href].
defaultValuestring—Uncontrolled initial HTML (normalised to the allowed tags).
onChange(html: string) =&gt; void—Fired with the normalised HTML on every change ("" when empty).
placeholderstring—
toolsRichTextTool[]—Which toolbar tools to show, in order. Default: all.
minHeightnumber | string—Minimum height of the editing area (px number or CSS length).
maxLengthnumber—Shows a "count / max" character hint (not enforced).
namestring—Form field name: the HTML submits via a hidden input.
formstring—Id of the form to submit with, when the editor sits outside it.
idstring—
width"xs" | "sm" | "md" | "lg" | "full"—Maximum width: "xs" (8rem) | "sm" (12rem) | "md" (20rem) | "lg" (36rem) | "full" (default). A cap, not a fixed width — it still shrinks on a phone or in a narrow FormRow column; the label and messages follow it. Sizes are the --field-width-* tokens.
classNamestring—