Overview
TheTextArea component supports rich text editing mode powered by Tiptap. When type="edit", it renders a full-featured WYSIWYG editor with formatting toolbar, supporting bold, italic, underline, headings, and text alignment.
Prerequisites
Install Required Packages
The rich text editor requires five Tiptap packages:For basic
TextArea with type="default", these dependencies are not required. Only install them if you need rich text editing functionality.Package Overview
| Package | Purpose |
|---|---|
@tiptap/react | Core React integration for Tiptap editor |
@tiptap/starter-kit | Essential extensions (bold, italic, headings, lists, etc.) |
@tiptap/extension-text-align | Text alignment support (left, center, right) |
@tiptap/extension-text-style | Base for custom text styling |
@tiptap/extensions | Additional extensions including Placeholder |
Basic Usage
RichTextEditor.tsx
Editor Features
The rich text editor includes a comprehensive formatting toolbar:Text Styles
- Paragraph - Regular text (default)
- Heading 1 - Large heading
- Heading 2 - Medium heading
Text Formatting
- Bold -
Ctrl/Cmd + B - Italic -
Ctrl/Cmd + I - Underline -
Ctrl/Cmd + U
Text Alignment
- Align Left - Default alignment
- Align Center - Center text
- Align Right - Right-align text
Component Props
Required Props
Must be set to
"edit" to enable rich text mode.Optional Props
HTML content to display in the editor. Supports HTML tags like
<p>, <h1>, <h2>, <strong>, <em>, <u>.Placeholder text shown when editor is empty.
Callback fired when editor content changes. Receives HTML string.
Custom styles for the editor container. Set
height to control editor size.Maximum character count. Currently tracked but not enforced by the editor.
Visual design variant. Affects toolbar and editor styling.
Custom component rendered in the top-right corner of the toolbar (e.g., a save button or action icon).
Advanced Usage
With Custom Toolbar Button
EditorWithActions.tsx
With Form Integration
BlogPostForm.tsx
Loading and Displaying HTML Content
DisplayPost.tsx
HTML Output
The editor outputs clean HTML with semantic tags:The HTML is safe to store in your database and render with
dangerouslySetInnerHTML or your preferred HTML sanitization library.Sanitizing HTML Output
For security, sanitize HTML before rendering user-generated content:Styling Customization
The editor uses internal CSS classes. Customize with CSS variables:globals.css
Keyboard Shortcuts
The editor supports standard keyboard shortcuts:| Action | Windows/Linux | macOS |
|---|---|---|
| Bold | Ctrl + B | Cmd + B |
| Italic | Ctrl + I | Cmd + I |
| Underline | Ctrl + U | Cmd + U |
| Heading 1 | Ctrl + Alt + 1 | Cmd + Alt + 1 |
| Heading 2 | Ctrl + Alt + 2 | Cmd + Alt + 2 |
| Paragraph | Ctrl + Alt + 0 | Cmd + Alt + 0 |
| Undo | Ctrl + Z | Cmd + Z |
| Redo | Ctrl + Shift + Z | Cmd + Shift + Z |
Comparison: Default vs. Rich Text Mode
| Feature | Default Mode (type="default") | Rich Text Mode (type="edit") |
|---|---|---|
| Dependencies | None | 5 Tiptap packages |
| Toolbar | None | Full formatting toolbar |
| Output | Plain text | HTML |
| Formatting | None | Bold, italic, underline, headings, alignment |
| Use Case | Simple text inputs | Blog posts, descriptions, rich content |
When to Use Default Mode
- Simple text inputs
- Comments or short descriptions
- No formatting needed
- Character limits important
When to Use Rich Text Mode
- Blog posts or articles
- Product descriptions with formatting
- Email templates
- Any content needing rich formatting
Troubleshooting
Editor doesn’t render
Solution
Solution
- Verify all 5 Tiptap packages are installed
- Check for console errors indicating missing dependencies
- Ensure
type="edit"is set correctly - Verify package versions are compatible (use same major version for all Tiptap packages)
Toolbar buttons don’t work
Solution
Solution
- Check browser console for JavaScript errors
- Ensure you’re not preventing default click behavior
- Verify the editor has focus (click inside the editor area)
Content doesn’t persist
Solution
Solution
- Use controlled component pattern with
valueandonChange - Store HTML in state:
const [content, setContent] = useState('') - Pass
value={content}andonChange={setContent}
Styling looks broken
Solution
Solution
- Import the editor CSS if using a custom build:
- Check for conflicting global CSS affecting
.ProseMirrorclass
Performance Considerations
The Tiptap editor adds ~50KB (gzipped) to your bundle. If you only need basic text input, use
type="default" instead to keep your bundle lean.-
Code Splitting: Lazy load the editor for better initial page load:
- Large Content: For very large documents (>10,000 words), consider implementing auto-save to prevent data loss
Next Steps
TextArea Component
View full component documentation and examples
Tiptap Documentation
Official Tiptap editor documentation
Optional Dependencies
Learn about other optional peer dependencies