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