Rich Text Editor

@allem-ui/rich-text

Lightweight WYSIWYG editor with formatting toolbar, keyboard shortcuts, and dark mode. Zero dependencies — built on native contentEditable.

Installation

npm install @allem-ui/rich-text

Add the @source directive to your CSS so Tailwind generates the component classes:

@source "@allem-ui/rich-text";

Editor

Full editor with toolbar. Try the formatting buttons and keyboard shortcuts.

Read-Only

Display formatted content without editing. Toolbar is automatically hidden.

Bubble Menu

Select text to reveal a floating toolbar with inline formatting options. The bubble menu appears automatically — hide the static toolbar for a distraction-free writing experience.

Hidden Toolbar

Use hideToolbar for a minimal writing experience. Keyboard shortcuts still work.

RichTextEditor Props

PropTypeDefaultDescription
initialValuestring""Initial HTML content
onChange(html: string) => voidCalled on content change with HTML string
placeholderstring"Start writing..."Placeholder text
readOnlybooleanfalseRead-only mode (hides toolbar)
minHeightnumber120Minimum editor height in pixels
maxHeightnumber400Maximum editor height in pixels
hideToolbarbooleanfalseHide the formatting toolbar
hideBubbleMenubooleanfalseHide the floating bubble menu on text selection
classNamestringAdditional CSS classes

useRichText

Hook for building a custom editor UI. Use this when you need full control over the toolbar and layout.

See the code example for composing a custom editor with useRichText.

Options

PropTypeDefaultDescription
initialValuestringInitial HTML content
onChange(html: string) => voidCalled when content changes

Return Value

PropTypeDefaultDescription
editorRefRefObject<HTMLDivElement>Ref to attach to the editable element
htmlstringCurrent HTML content
activeFormatsActiveFormatsObject of currently active formatting states
selectionRectSelectionRect | nullBounding rect of the current text selection
hasSelectionbooleanWhether text is currently selected
handleInput() => voidInput event handler
toggleBold() => voidToggle bold formatting
toggleItalic() => voidToggle italic formatting
toggleUnderline() => voidToggle underline formatting
toggleStrikethrough() => voidToggle strikethrough formatting
toggleHeading(level: 1 | 2 | 3) => voidToggle heading level
toggleOrderedList() => voidToggle ordered list
toggleUnorderedList() => voidToggle unordered list
toggleBlockquote() => voidToggle blockquote
toggleCodeBlock() => voidToggle code block
insertLink(url: string) => voidInsert a link at selection
removeLink() => voidRemove link from selection
insertHorizontalRule() => voidInsert a horizontal rule
undo() => voidUndo last action
redo() => voidRedo last undone action

BubbleMenu Props

Floating inline toolbar that appears on text selection. Built into RichTextEditor by default — use standalone with useRichText for custom layouts.

PropTypeDefaultDescription
editorRef*RefObject<HTMLDivElement>Ref to the editable element
selectionRect*SelectionRect | nullBounding rect of the current selection
hasSelection*booleanWhether text is currently selected
activeFormats*ActiveFormatsCurrently active formatting states
onBold*() => voidToggle bold
onItalic*() => voidToggle italic
onUnderline*() => voidToggle underline
onStrikethrough*() => voidToggle strikethrough
onLink*(url: string) => voidInsert a link
onRemoveLink*() => voidRemove a link

RichTextToolbar Props

Standalone toolbar component for custom editor layouts via useRichText.

PropTypeDefaultDescription
activeFormats*ActiveFormatsCurrent formatting state
onBold*() => voidToggle bold
onItalic*() => voidToggle italic
onUnderline*() => voidToggle underline
onStrikethrough*() => voidToggle strikethrough
onHeading*(level: 1 | 2 | 3) => voidToggle heading level
onOrderedList*() => voidToggle ordered list
onUnorderedList*() => voidToggle unordered list
onBlockquote*() => voidToggle blockquote
onCodeBlock*() => voidToggle code block
onLink*(url: string) => voidInsert link
onRemoveLink*() => voidRemove link
onUndo() => voidUndo action
onRedo() => voidRedo action
classNamestringAdditional CSS classes

RichTextContent Props

The editable content area. Use with useRichText for custom layouts.

PropTypeDefaultDescription
editorRef*RefObject<HTMLDivElement>Ref from useRichText
initialValuestring""Initial HTML content
placeholderstring"Start writing..."Placeholder text
readOnlybooleanfalseDisable editing
minHeightnumber120Minimum height in pixels
maxHeightnumber400Maximum height in pixels
onInput*() => voidInput handler from useRichText
onKeyDown(e: KeyboardEvent) => voidKeyboard event handler
classNamestringAdditional CSS classes
childrenReactNodeOverlay elements like BubbleMenu

ActiveFormats Type

PropTypeDefaultDescription
boldbooleanBold is active
italicbooleanItalic is active
underlinebooleanUnderline is active
strikethroughbooleanStrikethrough is active
orderedListbooleanOrdered list is active
unorderedListbooleanUnordered list is active
blockquotebooleanBlockquote is active
codebooleanCode block is active
heading1booleanHeading 1 is active
heading2booleanHeading 2 is active
heading3booleanHeading 3 is active

SelectionRect Type

PropTypeDefaultDescription
topnumberTop position in pixels
leftnumberLeft position in pixels
widthnumberSelection width in pixels
heightnumberSelection height in pixels

Keyboard Shortcuts

FormatShortcut
Bold⌘B
Italic⌘I
Underline⌘U
Undo⌘Z
Redo⌘⇧Z

Markdown Shortcuts

Type these at the start of a new line to auto-convert into formatted blocks.

InputResult
# Heading 1
## Heading 2
### Heading 3
> Blockquote
- or * Unordered list
1. Ordered list
```Code block
--- Horizontal rule

Toolbar Formats

The toolbar supports: Bold, Italic, Underline, Strikethrough, Heading 1–3, Ordered List, Unordered List, Blockquote, Code Block, Link, Undo, and Redo.