Syncfusion React Block Editor in React
Component Overview
The Syncfusion React BlockEditorComponent is a powerful block-based rich text editor that allows users to create, edit, and format content using a modern block architecture. Each piece of content (paragraphs, headings, lists, tables, code snippets) is a discrete, manageable block.
Key Capabilities
The BlockEditorComponent provides:
- Block-based architecture - Content structured as discrete, reorderable blocks
- Built-in block types - Paragraphs, headings, lists, tables, code, callouts, quotes, collapsible sections
- Intuitive menus - Slash commands, context menus, inline toolbars
- Drag-and-drop - Reorder blocks easily with visual handles
- Content export - Export as JSON, HTML, or plain text
- Accessibility - WCAG 2.1 compliant with keyboard navigation and screen reader support
- Customization - Custom styling, themes, RTL support, globalization
- Collaborative Editing - Real-time multi-user editing powered by Yjs, with user presence and remote cursors, document version history and snapshot management
Documentation Navigation Guide
Getting Started
📄 Read: references/getting-started.md
- Installation and npm package setup
- Basic component implementation
- CSS imports and theme configuration
- Creating your first block editor
- Setting initial content with blocks
Built-in Block Types
📄 Read: references/built-in-blocks.md
- Block type reference (Paragraph, Heading, List, Table, Code, Quote, Callout)
- Nested block types (CollapsibleHeading, CollapsibleParagraph)
- Block indentation and CSS class styling
- Content configuration and properties
Menus and Commands
📄 Read: references/block-editor-menus.md
- Slash command menu customization
- Context menu configuration with Table and Link options
- Inline toolbar setup with Transform, code, link, and color support
- Block action menu customization and tooltips
- Menu events and filtering
Drag-Drop and Content Management
📄 Read: references/drag-drop-and-content.md
- Drag-and-drop block reordering (
enableDragAndDrop)
- Content insertion and nesting
- Drag events (
blockDragStart, blockDragging, blockDropped)
- Programmatic block movement
Mentions and Labels
📄 Read: references/mentions-and-labels.md
users prop and UserModel interface for @mention feature
labelSettings prop and LabelItemModel interface for label feature
ContentType.Mention / ContentType.Label inline content
IMentionContentSettings / ILabelContentSettings
Methods and API
📄 Read: references/methods-and-api.md
- Block management methods (add, remove, update, move)
- Selection and cursor control
- Data export/import (JSON, HTML)
- Content formatting and rendering
Styling and Appearance
📄 Read: references/styling-and-appearance.md
- CSS theming and imports
- Block styling with custom CSS classes
- Typography and formatting options
- Dark mode and responsive design
Advanced Features
📄 Read: references/advanced-features.md
- Paste cleanup and content sanitization
- Undo/redo functionality
- Keyboard shortcut customization
- Read-only mode configuration
- XSS protection and HTML sanitization
- RTL support and internationalization
Collaborative Editing
📄 Read: references/collaborative-editing.md
- Real-time collaborative editing powered by Yjs (CRDT-based sync and conflict resolution)
- Injecting the
Collaboration and VersionHistory modules
collaborationSettings property (provider, adapter, enableAwareness, versionHistory)
- Choosing a Yjs provider (y-websocket, y-webrtc, y-indexeddb, Hocuspocus, Liveblocks, PartyKit)
- Setting up a Yjs document,
YjsAdapter, and provider
- User presence, remote cursors, and text selection overlays (enableAwareness)
- Configuring the current user via
users and currentUserId
- Version history: creating, listing, renaming, restoring, comparing, exporting, and importing snapshots
- Custom snapshot storage via the
IVersionStorage interface
- Version history events:
snapshotCreated, snapshotRestored
Accessibility
📄 Read: references/accessibility.md
- WCAG 2.1 compliance
- Keyboard navigation patterns
- Screen reader support and ARIA attributes
- Focus management
- Color contrast and visual indicators
Quick Start Example
import { BlockEditorComponent } from '@syncfusion/ej2-react-blockeditor';
import { BlockModel, ContentType } from '@syncfusion/ej2-react-blockeditor';
import '@syncfusion/ej2-react-blockeditor/styles/material.css';
function App() {
// Define initial blocks
const blocksData: BlockModel[] = [
{
id: 'block-1',
blockType: 'Heading',
properties: { level: 1 },
content: [
{
contentType: ContentType.Text,
content: 'Welcome to Block Editor'
}
]
},
{
id: 'block-2',
blockType: 'Paragraph',
content: [
{
contentType: ContentType.Text,
content: 'This is your first paragraph. Click the "+" button to add more blocks.'
}
]
}
];
return (
<BlockEditorComponent
id="block-editor"
blocks={blocksData}
/>
);
}
export default App;
Common Patterns
1. Add a Block Programmatically
const editorRef = React.useRef<BlockEditorComponent>(null);
const addNewBlock = () => {
const newBlock: BlockModel = {
blockType: 'Paragraph',
content: [
{
contentType: ContentType.Text,
content: 'New paragraph block'
}
]
};
editorRef.current?.addBlock(newBlock);
};
2. Handle Menu Item Selection
const commandMenuSettings = {
itemSelect: (args) => {
console.log('Selected command:', args.command.label, args.command.id);
// Handle custom actions based on selected command
}
};
3. Export Content as JSON
const exportContent = () => {
const jsonContent = editorRef.current?.getDataAsJson();
console.log('Exported content:', jsonContent);
};
4. Enable Read-Only Mode
<BlockEditorComponent
id="block-editor"
blocks={blocksData}
readOnly={true}
/>
Key Props
⚠️ Props toolbarSettings, containerCssClass, and showBlockHandle do not exist in the BlockEditor API and must not be used.
| Prop |
Type |
Description |
id |
string |
Unique identifier for the component |
blocks |
BlockModel[] |
Array of block objects defining content |
readOnly |
boolean |
Enable read-only mode (default: false) |
width |
string | number |
Width of the editor container (default: '100%') |
height |
string | number |
Height of the editor container |
commandMenuSettings |
CommandMenuSettingsModel |
Customize slash command (/) menu |
contextMenuSettings |
ContextMenuSettingsModel |
Configure right-click context menu |
inlineToolbarSettings |
InlineToolbarSettingsModel |
Configure inline text selection toolbar |
blockActionMenuSettings |
BlockActionMenuSettingsModel |
Configure block action (⋮) menu |
transformSettings |
TransformSettingsModel |
Configure block type transform menu |
imageBlockSettings |
ImageBlockSettingsModel |
Configure image upload and rendering |
codeBlockSettings |
CodeBlockSettingsModel |
Configure code block languages |
pasteCleanupSettings |
PasteCleanupSettingsModel |
Control paste sanitization behavior |
users |
UserModel[] |
User list for @mention feature and collaboration presence with avatar colors |
labelSettings |
LabelSettingsModel |
Label items and trigger char for label feature |
enableDragAndDrop |
boolean |
Enable/disable drag-and-drop reordering (default: true) |
undoRedoStack |
number |
Max number of undo/redo history steps |
keyConfig |
{ [key: string]: string } |
Custom keyboard shortcut mappings |
locale |
string |
Localization language code (default: 'en-US') |
blockChanged |
EmitType<BlockChangedEventArgs> |
Fires when block content changes |
collaborationSettings |
CollaborationSettingsModel |
Configure real-time collaboration with Yjs provider, awareness, and version history |
currentUserId |
string |
Unique identifier of the current user for collaboration and cursor identification |
Common Use Cases
Content Management System - Build a CMS with block-based editing, custom block types, and content export
Document Editor - Create a collaborative document editor with formatting, templates, and version control
Note-Taking App - Implement a personal notes app with nesting, tagging, and search capabilities
Blog Editor - Enable blog authors to write with rich formatting, media embeds, and preview
Knowledge Base - Build internal documentation with organized blocks, search, and linked references
Survey/Form Builder - Create dynamic surveys with conditional blocks and response capture
1---2name: syncfusion-react-blockeditor3description: Implement the Syncfusion React BlockEditor component for block-based content editing. Use this skill for block-based rich content editing, document creation, CMS interfaces, markdown alternatives, editor setup, block configuration, toolbar or menu customization, drag-and-drop behavior, formatting options, APIs, accessibility, real-time collaborative editing with Yjs integration, user presence and remote cursors, document version history and snapshot management in React.4---5
6# Syncfusion React Block Editor in React
7
8## Component Overview
9
10The Syncfusion React BlockEditorComponent is a powerful block-based rich text editor that allows users to create, edit, and format content using a modern block architecture. Each piece of content (paragraphs, headings, lists, tables, code snippets) is a discrete, manageable block.
11
12### Key Capabilities
13
14The BlockEditorComponent provides:
15- **Block-based architecture** - Content structured as discrete, reorderable blocks
16- **Built-in block types** - Paragraphs, headings, lists, tables, code, callouts, quotes, collapsible sections
17- **Intuitive menus** - Slash commands, context menus, inline toolbars
18- **Drag-and-drop** - Reorder blocks easily with visual handles
19- **Content export** - Export as JSON, HTML, or plain text
20- **Accessibility** - WCAG 2.1 compliant with keyboard navigation and screen reader support
21- **Customization** - Custom styling, themes, RTL support, globalization
22- **Collaborative Editing** - Real-time multi-user editing powered by Yjs, with user presence and remote cursors, document version history and snapshot management
23
24## Documentation Navigation Guide
25
26### Getting Started
27📄 **Read:** [references/getting-started.md](references/getting-started.md)
28- Installation and npm package setup
29- Basic component implementation
30- CSS imports and theme configuration
31- Creating your first block editor
32- Setting initial content with blocks
33
34### Built-in Block Types
35📄 **Read:** [references/built-in-blocks.md](references/built-in-blocks.md)
36- Block type reference (Paragraph, Heading, List, Table, Code, Quote, Callout)
37- Nested block types (CollapsibleHeading, CollapsibleParagraph)
38- Block indentation and CSS class styling
39- Content configuration and properties
40
41### Menus and Commands
42📄 **Read:** [references/block-editor-menus.md](references/block-editor-menus.md)
43- Slash command menu customization
44- Context menu configuration with Table and Link options
45- Inline toolbar setup with Transform, code, link, and color support
46- Block action menu customization and tooltips
47- Menu events and filtering
48
49### Drag-Drop and Content Management
50📄 **Read:** [references/drag-drop-and-content.md](references/drag-drop-and-content.md)
51- Drag-and-drop block reordering (`enableDragAndDrop`)
52- Content insertion and nesting
53- Drag events (`blockDragStart`, `blockDragging`, `blockDropped`)
54- Programmatic block movement
55
56### Mentions and Labels
57📄 **Read:** [references/mentions-and-labels.md](references/mentions-and-labels.md)
58- `users` prop and `UserModel` interface for `@mention` feature
59- `labelSettings` prop and `LabelItemModel` interface for label feature
60- `ContentType.Mention` / `ContentType.Label` inline content
61- `IMentionContentSettings` / `ILabelContentSettings`
62
63### Methods and API
64📄 **Read:** [references/methods-and-api.md](references/methods-and-api.md)
65- Block management methods (add, remove, update, move)
66- Selection and cursor control
67- Data export/import (JSON, HTML)
68- Content formatting and rendering
69
70### Styling and Appearance
71📄 **Read:** [references/styling-and-appearance.md](references/styling-and-appearance.md)
72- CSS theming and imports
73- Block styling with custom CSS classes
74- Typography and formatting options
75- Dark mode and responsive design
76
77### Advanced Features
78📄 **Read:** [references/advanced-features.md](references/advanced-features.md)
79- Paste cleanup and content sanitization
80- Undo/redo functionality
81- Keyboard shortcut customization
82- Read-only mode configuration
83- XSS protection and HTML sanitization
84- RTL support and internationalization
85
86### Collaborative Editing
87📄 **Read:** [references/collaborative-editing.md](references/collaborative-editing.md)
88- Real-time collaborative editing powered by Yjs (CRDT-based sync and conflict resolution)
89- Injecting the `Collaboration` and `VersionHistory` modules
90- `collaborationSettings` property (provider, adapter, enableAwareness, versionHistory)
91- Choosing a Yjs provider (y-websocket, y-webrtc, y-indexeddb, Hocuspocus, Liveblocks, PartyKit)
92- Setting up a Yjs document, `YjsAdapter`, and provider
93- User presence, remote cursors, and text selection overlays (enableAwareness)
94- Configuring the current user via `users` and `currentUserId`
95- Version history: creating, listing, renaming, restoring, comparing, exporting, and importing snapshots
96- Custom snapshot storage via the `IVersionStorage` interface
97- Version history events: `snapshotCreated`, `snapshotRestored`
98
99### Accessibility
100📄 **Read:** [references/accessibility.md](references/accessibility.md)
101- WCAG 2.1 compliance
102- Keyboard navigation patterns
103- Screen reader support and ARIA attributes
104- Focus management
105- Color contrast and visual indicators
106
107## Quick Start Example
108
109```tsx
110import { BlockEditorComponent } from '@syncfusion/ej2-react-blockeditor';
111import { BlockModel, ContentType } from '@syncfusion/ej2-react-blockeditor';
112import '@syncfusion/ej2-react-blockeditor/styles/material.css';
113
114function App() {
115 // Define initial blocks
116 const blocksData: BlockModel[] = [
117 {
118 id: 'block-1',
119 blockType: 'Heading',
120 properties: { level: 1 },
121 content: [
122 {
123 contentType: ContentType.Text,
124 content: 'Welcome to Block Editor'
125 }
126 ]
127 },
128 {
129 id: 'block-2',
130 blockType: 'Paragraph',
131 content: [
132 {
133 contentType: ContentType.Text,
134 content: 'This is your first paragraph. Click the "+" button to add more blocks.'
135 }
136 ]
137 }
138 ];
139
140 return (
141 <BlockEditorComponent
142 id="block-editor"
143 blocks={blocksData}
144 />
145 );
146}
147
148export default App;
149```
150
151## Common Patterns
152
153### 1. Add a Block Programmatically
154
155```tsx
156const editorRef = React.useRef<BlockEditorComponent>(null);
157
158const addNewBlock = () => {
159 const newBlock: BlockModel = {
160 blockType: 'Paragraph',
161 content: [
162 {
163 contentType: ContentType.Text,
164 content: 'New paragraph block'
165 }
166 ]
167 };
168
169 editorRef.current?.addBlock(newBlock);
170};
171```
172
173### 2. Handle Menu Item Selection
174
175```tsx
176const commandMenuSettings = {
177 itemSelect: (args) => {
178 console.log('Selected command:', args.command.label, args.command.id);
179 // Handle custom actions based on selected command
180 }
181};
182```
183
184### 3. Export Content as JSON
185
186```tsx
187const exportContent = () => {
188 const jsonContent = editorRef.current?.getDataAsJson();
189 console.log('Exported content:', jsonContent);
190};
191```
192
193### 4. Enable Read-Only Mode
194
195```tsx
196<BlockEditorComponent
197 id="block-editor"
198 blocks={blocksData}
199 readOnly={true}
200/>
201```
202
203## Key Props
204
205> ⚠️ Props `toolbarSettings`, `containerCssClass`, and `showBlockHandle` do **not** exist in the BlockEditor API and must not be used.
206
207| Prop | Type | Description |
208|------|------|-------------|
209| `id` | `string` | Unique identifier for the component |
210| `blocks` | `BlockModel[]` | Array of block objects defining content |
211| `readOnly` | `boolean` | Enable read-only mode (default: `false`) |
212| `width` | `string \| number` | Width of the editor container (default: `'100%'`) |
213| `height` | `string \| number` | Height of the editor container |
214| `commandMenuSettings` | `CommandMenuSettingsModel` | Customize slash command (/) menu |
215| `contextMenuSettings` | `ContextMenuSettingsModel` | Configure right-click context menu |
216| `inlineToolbarSettings` | `InlineToolbarSettingsModel` | Configure inline text selection toolbar |
217| `blockActionMenuSettings` | `BlockActionMenuSettingsModel` | Configure block action (⋮) menu |
218| `transformSettings` | `TransformSettingsModel` | Configure block type transform menu |
219| `imageBlockSettings` | `ImageBlockSettingsModel` | Configure image upload and rendering |
220| `codeBlockSettings` | `CodeBlockSettingsModel` | Configure code block languages |
221| `pasteCleanupSettings` | `PasteCleanupSettingsModel` | Control paste sanitization behavior |
222| `users` | `UserModel[]` | User list for `@mention` feature and collaboration presence with avatar colors |
223| `labelSettings` | `LabelSettingsModel` | Label items and trigger char for label feature |
224| `enableDragAndDrop` | `boolean` | Enable/disable drag-and-drop reordering (default: `true`) |
225| `undoRedoStack` | `number` | Max number of undo/redo history steps |
226| `keyConfig` | `{ [key: string]: string }` | Custom keyboard shortcut mappings |
227| `locale` | `string` | Localization language code (default: `'en-US'`) |
228| `blockChanged` | `EmitType<BlockChangedEventArgs>` | Fires when block content changes |
229| `collaborationSettings` | `CollaborationSettingsModel` | Configure real-time collaboration with Yjs provider, awareness, and version history |
230| `currentUserId` | `string` | Unique identifier of the current user for collaboration and cursor identification |
231
232## Common Use Cases
233
234**Content Management System** - Build a CMS with block-based editing, custom block types, and content export
235
236**Document Editor** - Create a collaborative document editor with formatting, templates, and version control
237
238**Note-Taking App** - Implement a personal notes app with nesting, tagging, and search capabilities
239
240**Blog Editor** - Enable blog authors to write with rich formatting, media embeds, and preview
241
242**Knowledge Base** - Build internal documentation with organized blocks, search, and linked references
243
244**Survey/Form Builder** - Create dynamic surveys with conditional blocks and response capture
245
246---