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 barWhen 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
| Prop | Type | Required | Description |
|---|---|---|---|
label | React.ReactNode | — | |
description | React.ReactNode | — | Helper text under the label; linked via aria-describedby. |
hint | React.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. |
errorMessage | React.ReactNode | — | Shown when isInvalid; announced and linked via aria-describedby. |
isRequired | boolean | — | Blocks native submit while the editor has no text. |
isInvalid | boolean | — | |
isDisabled | boolean | — | |
value | string | — | Controlled value: HTML limited to b/strong, i/em, u, ul, ol, li, p, br and a[href]. |
defaultValue | string | — | Uncontrolled initial HTML (normalised to the allowed tags). |
onChange | (html: string) => void | — | Fired with the normalised HTML on every change ("" when empty). |
placeholder | string | — | |
tools | RichTextTool[] | — | Which toolbar tools to show, in order. Default: all. |
minHeight | number | string | — | Minimum height of the editing area (px number or CSS length). |
maxLength | number | — | Shows a "count / max" character hint (not enforced). |
name | string | — | Form field name: the HTML submits via a hidden input. |
form | string | — | Id of the form to submit with, when the editor sits outside it. |
id | string | — | |
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. |
className | string | — |