Rich Text Editor

A rich text editor built on Tiptap with bold, italic, and link support. Pick the marks a field allows, and add your own extensions and toolbar items.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/rich-text-editor.json

Usage

import { RichTextEditor, RichTextEditorButton } from "@/components/ui/rich-text-editor"

Examples

Default

Bold, italic, and links, with a toolbar above the writing area. value and onChange deal in HTML strings, not markdown, so store what you get back as-is.

Only some marks

marks picks the formatting a field allows, and each mark gets its button. A mark left out is off for shortcuts and pastes too, so the saved HTML holds only what the field can use.

Your own toolbar items

toolbar adds items after the mark buttons and is handed the live editor. Build them from RichTextEditorButton so they match. New node types come in through extensions and need styling through className.

A whole document

variant="document" drops the field frame for a whole piece: the toolbar pins to the top while the text scrolls, and the text takes the Prose look. Put it on a card, in a ScrollFade with fade="bottom" so the fade never covers the toolbar.

States

Default, read-only and disabled side by side. Read-only sits flat on the muted fill at full opacity, hides the toolbar and still takes focus, so its text can be selected and copied; disabled dims to 70% and does not.

API Reference

PropTypeDefaultDescription
value*stringNoneThe editor content as an HTML string.
onChange*(value: string) => voidNoneCalled with the updated HTML string on every edit.
onBlur() => voidNoneCalled when the editor loses focus.
placeholderstringNonePlaceholder text shown when the editor is empty.
disabledbooleanfalseTurns the editor off: not editable, not focusable, toolbar disabled, dimmed to 70% like a disabled Textarea. Inside a Field the field's own disabled does the same.
readOnlybooleanfalseShows the content without letting it be changed: flat on the muted fill at full opacity, toolbar hidden, still focusable so the text can be selected and copied. Ignored while disabled.
marks("bold" | "italic" | "link")[]["bold", "italic", "link"]The marks the editor applies, each with its toolbar button. A mark left out is off for shortcuts and pastes too. An empty list with no toolbar hides the toolbar. Read once, on mount.
extensionsExtensionsNoneMore Tiptap extensions, added after the kit's own. Read once, on mount.
toolbar(editor: Editor | null) => ReactNodeNoneMore toolbar items after the mark buttons, given the live editor (null until it mounts).
variant"field" | "document""field"field is a form field framed like a Textarea. document is a whole piece with no frame: the toolbar is a band across the whole surface, pinned to the top of the scroll area, and its buttons and the text share one reading column in the Prose look. Read once, on mount.
activeRichTextEditorButtonbooleanNoneFills the button with the accent tint and sets aria-pressed. Leave it off for a button that is not a toggle. Takes Button's other props; give it an aria-label and a size-3 icon.
classNamestringNoneExtra classes for the editor's outer container.
idstringNoneId for the editable area, for a <label htmlFor> outside a Field. Inside a Field the id comes from the field.
aria-label / aria-labelledby / aria-describedby / aria-invalidstring | booleanNonePut on the editable area. Inside a Field the label, help and error links and the invalid state arrive on their own, and clicking the label focuses the editor.
value*stringThe editor content as an HTML string.
onChange*(value: string) => voidCalled with the updated HTML string on every edit.
onBlur() => voidCalled when the editor loses focus.
placeholderstringPlaceholder text shown when the editor is empty.
disabledboolean = falseTurns the editor off: not editable, not focusable, toolbar disabled, dimmed to 70% like a disabled Textarea. Inside a Field the field's own disabled does the same.
readOnlyboolean = falseShows the content without letting it be changed: flat on the muted fill at full opacity, toolbar hidden, still focusable so the text can be selected and copied. Ignored while disabled.
marks("bold" | "italic" | "link")[] = ["bold", "italic", "link"]The marks the editor applies, each with its toolbar button. A mark left out is off for shortcuts and pastes too. An empty list with no toolbar hides the toolbar. Read once, on mount.
extensionsExtensionsMore Tiptap extensions, added after the kit's own. Read once, on mount.
toolbar(editor: Editor | null) => ReactNodeMore toolbar items after the mark buttons, given the live editor (null until it mounts).
variant"field" | "document" = "field"field is a form field framed like a Textarea. document is a whole piece with no frame: the toolbar is a band across the whole surface, pinned to the top of the scroll area, and its buttons and the text share one reading column in the Prose look. Read once, on mount.
activeRichTextEditorButtonbooleanFills the button with the accent tint and sets aria-pressed. Leave it off for a button that is not a toggle. Takes Button's other props; give it an aria-label and a size-3 icon.
classNamestringExtra classes for the editor's outer container.
idstringId for the editable area, for a <label htmlFor> outside a Field. Inside a Field the id comes from the field.
aria-label / aria-labelledby / aria-describedby / aria-invalidstring | booleanPut on the editable area. Inside a Field the label, help and error links and the invalid state arrive on their own, and clicking the label focuses the editor.