Toolbar in EJ2 TypeScript Rich Text Editor Control
7 Mar 202524 minutes to read
The Syncfusion EJ2 TypeScript Rich Text Editor control provides a versatile and powerful toolbar to enhance your text editing experience. The toolbar contains a variety of formatting, styling, and editing tools, allowing users to create and modify content efficiently.
Tools
Default Toolbar Items
By default, the Rich Text Editor displays the following toolbar items:
Bold
,Italic
,Underline
,|
,Formats
,Alignments
,Blockquote
,OrderedList
,UnorderedList
,|
,CreateLink
,Image
,|
,SourceCode
,Undo
,Redo
These default items cover essential text editing features, such as text formatting, lists, alignment, and linking.
Available Toolbar Items
The following table shows the list of available tools in the Rich Text Editor’s toolbar.
The order of items in the toolbar can be customized to meet your application’s requirements. If no specific order is set, the editor will render the above default toolbar items. Below is a list of all available toolbar items in the Rich Text Editor.
Text formatting
It provides tools for applying text styles such as bold, italic, underline, strike-through, and more to modify the appearance of the text.
Name | Icons | Summary | Initialization |
---|---|---|---|
Bold | ![]() |
Text that is thicker and darker than usual. | toolbarSettings: { items: [‘Bold’]} |
Italic | ![]() |
Shows a text that is leaned to the right. | toolbarSettings: { items: [‘Italic’]} |
Underline | ![]() |
The underline is added to the selected text. | toolbarSettings: { items: [‘Underline’]} |
StrikeThrough | ![]() |
Apply double line strike through formatting for the selected text. | toolbarSettings: { items: [‘StrikeThrough’]} |
ClearFormat | ![]() |
The clear format tool is useful to remove all formatting styles (such as bold, italic, underline, color, superscript, subscript, and more) from currently selected text. As a result, all the text formatting will be cleared and return to its default formatting styles. | toolbarSettings: { items: [‘ClearFormat’]} |
Blockquote | ![]() |
Blockquotes visually highlight important text within an editor, emphasizing key information or quotations. | toobarSettings: { items: [‘Blockquote’]} |
SubScript | ![]() |
Makes the selected text as subscript (lower). | toolbarSettings: { items: [‘SubScript’]} |
SuperScript | ![]() |
Makes the selected text as superscript (higher). | toolbarSettings: { items: [‘SuperScript’]} |
LowerCase | ![]() |
Change the case of selected text to lower in the content. | toolbarSettings: { items: [‘LowerCase’]} |
UpperCase | ![]() |
Change the case of selected text to upper in the content. | toolbarSettings: { items: [‘UpperCase’’]} |
Font & styling
Tools in this section allow users to customize font properties such as font family, size, color, background color, and paragraph formatting.
Name | Icons | Summary | Initialization |
---|---|---|---|
FontName | ![]() |
Defines the fonts that appear under the Font Family DropDownList from the Rich Text Editor’s toolbar. | toolbarSettings: { items: [‘FontName’]} |
FontSize | ![]() |
Defines the font sizes that appear under the Font Size DropDownList from the Rich Text Editor’s toolbar. | toolbarSettings: { items: [‘FontSize’]} |
FontColor | ![]() |
Specifies an array of colors can be used in the colors popup for font color. | toolbarSettings: { items: [‘FontColor’]} |
BackgroundColor | ![]() |
Specifies an array of colors can be used in the colors popup for background color. | toolbarSettings: { items: [‘BackgroundColor’]} |
Formats (Paragraph, Headings) | ![]() |
An Object with the options that will appear in the Paragraph Format dropdown from the toolbar. | toolbarSettings: { items: [‘Formats’]} |
Alignment
This section provides alignment options for the text or content, allowing users to justify text or align it to the left, center, or right.
Name | Icons | Summary | Initialization |
---|---|---|---|
Alignment | ![]() |
Align the content with left, center, and right margin. | toolbarSettings: { items: [‘Alignments’]} |
JustifyLeft | ![]() |
Allows each line to begin at the same distance from the editor’s left-hand side. | toolbarSettings: { items: [‘JustifyLeft’]} |
JustifyCenter | ![]() |
There is an even space on each side of each line since the text is not aligned to the left or right margins. | toolbarSettings: { items: [‘JustifyCenter’]} |
JustifyRight | ![]() |
Allows each line to end at the same distance from the editor’s right-hand side. | toolbarSettings: { items: [‘JustifyRight’]} |
JustifyFull | ![]() |
The text is aligned with both right and left margins. | toolbarSettings: { items: [‘JustifyFull’]} |
Lists & indentation
Tools here allow users to create ordered and unordered lists, change the list style, and adjust indentation levels for improved document structure.
Name | Icons | Summary | Initialization |
---|---|---|---|
OrderedList | ![]() |
Create a new list item(numbered). | toolbarSettings: { items: [‘OrderedList’]} |
UnorderedList | ![]() |
Create a new list item(bulleted). | toolbarSettings: { items: [‘UnorderedList’]} |
NumberFormatList | ![]() |
Allows to create list items with various list style types(numbered). | toolbarSettings: { items: [‘NumberFormatList’]} |
BulletFormatList | ![]() |
Allows to create list items with various list style types(bulleted). | toolbarSettings: { items: [‘BulletFormatList’]} |
Indent | ![]() |
Allows to increase the indent level of the content. | toolbarSettings: { items: [‘Indent’]} |
Outdent | ![]() |
Allows to decrease the indent level of the content. | toolbarSettings: { items: [‘Outdent’]} |
Hyperlinks
This section provides tools for inserting and managing hyperlinks within the content. Users can create new links or modify existing ones to enhance document navigation and interactivity.
Name | Icons | Summary | Initialization |
---|---|---|---|
Hyperlink | ![]() |
Creates a hyperlink to a text or image to a specific location in the content. | toolbarSettings: { items: [‘CreateLink’]} |
InsertLink | ![]() |
Allows users to add a link to a particular item. | toolbarSettings: { items: [‘InsertLink’]} |
Link quicktoolbar items
The link quicktoolbar provides tools to manage hyperlinks in the Rich Text Editor, allowing users to add, edit, or remove links from selected text or images directly within the editor.
Name | Icons | Summary | Initialization |
---|---|---|---|
OpenLink | ![]() |
To open the URL link that is attached to the selected text. | quickToolbarSettings: { link: [‘OpenLink’]} |
EditLink | ![]() |
Allows you to change the URL that has been attached to a specific item. | quickToolbarSettings: { link: [‘EditLink’]} |
RemoveLink | ![]() |
Allows you to remove the applied link from the selected item. | quickToolbarSettings: { link: [‘RemoveLink’]} |
Images
This section contains the primary tool for inserting images into the editor.
Name | Icons | Summary | Initialization |
---|---|---|---|
Insert Image | ![]() |
Inserts an image from an online source or local computer. | toolbarSettings: { items: [‘Image’]} |
Image quicktoolbar items
The image quicktoolbar offers a set of tools to edit images inserted in the Rich Text Editor. It allows users to modify image properties, including alignment, size, alternate text, and links, enhancing image management in the content.
Name | Icons | Summary | Initialization |
---|---|---|---|
Replace Image | ![]() |
Replace the selected image with another image. | quickToolbarSettings: { image: [‘Replace’]} |
Align Image | ![]() |
The image can be aligned to the right, left, or center. | quickToolbarSettings: { image: [‘Align’]} |
Remove Image | ![]() |
Allows to remove the selected image from the editor. | quickToolbarSettings: { image: [‘Remove’]} |
OpenImageLink | ![]() |
Opens the link that is attached to the selected image. | quickToolbarSettings: { image: [‘OpenImageLink’]} |
EditImageLink | ![]() |
Allows to edit the link that is attached to the selected image. | quickToolbarSettings: { image: [‘EditImageLink’]} |
RemoveImageLink | ![]() |
Removes the link that is attached to the selected image. | quickToolbarSettings: { image: [‘RemoveImageLink’]} |
Display | ![]() |
Allows you to choose whether an image should be shown inline or as a block. | quickToolbarSettings: { image: [‘Display’]} |
AltText | ![]() |
To display image description when an image on a Web page cannot be displayed. | quickToolbarSettings: { image: [‘AltText’]} |
Dimension | ![]() |
Allows you to customize the image’s height and width. | quickToolbarSettings: { image: [‘Dimension’]} |
Tables
This section offers the main tool for creating tables within the content.
Name | Icons | Summary | Initialization |
---|---|---|---|
CreateTable | ![]() |
Create a table with defined columns and rows. | toolbarSettings: { items: [‘CreateTable’]} |
Table quicktoolbar items
The table quicktoolbar provides options for table editing within the Rich Text Editor. Users can insert or remove rows and columns, merge or split cells, and access table properties for easier table management and customization.
Name | Icons | Summary | Initialization |
---|---|---|---|
RemoveTable | ![]() |
Removes the selected table and its contents. | quickToolbarSettings: { table: [‘TableRemove’]} |
TableHeader | ![]() |
Allows you to add a table header. | quickToolbarSettings: { table: [‘TableHeader’]} |
TableColumns | ![]() |
Shows the dropdown to insert a column or delete the selected column. | quickToolbarSettings: { table: [‘TableColumns’]} |
TableRows | ![]() |
Shows the dropdown to insert a row ors delete the selected row. | quickToolbarSettings: { table: [‘TableRows’]} |
TableCellHorizontalAlign | ![]() |
Allows the table cell content to be aligned horizontally. | quickToolbarSettings: { table: [‘TableCellHorizontalAlign’]} |
TableCellVerticalAlign | ![]() |
Allows the table cell content to be aligned vertically. | quickToolbarSettings: { table: [‘TableCellVerticalAlign’]} |
TableEditProperties | ![]() |
Allows you to change the table width, padding, and cell spacing styles. | quickToolbarSettings: { table: [‘TableEditProperties’]} |
Undo & redo
These tools allow users to easily undo or redo any changes made within the editor to restore or repeat previous actions.
Name | Icons | Summary | Initialization |
---|---|---|---|
Undo | ![]() |
Allows to undo the actions. | toolbarSettings: { items: [‘Undo’]} |
Redo | ![]() |
Allows to redo the actions. | toolbarSettings: { items: [‘Redo’]} |
Other tools
This section contains miscellaneous tools such as full-screen mode, print, preview, source code editing, and clearing all styles from text.
Name | Icons | Summary | Initialization |
---|---|---|---|
FullScreen | ![]() |
Stretches the editor to the maximum width and height of the browser window. | toolbarSettings: { items: [‘FullScreen’]} |
Maximize | ![]() |
Stretches the editor to the maximum width and height of the browser window. | toolbarSettings: { items: [‘Maximize’]} |
Minimize | ![]() |
Shrinks the editor to the default width and height. | toolbarSettings: { items: [‘Minimize’]} |
Preview | ![]() |
Allows to see how the editor’s content looks in a browser. | toolbarSettings: { items: [‘Preview’]} |
InsertCode | ![]() |
Represents preformatted text which is to be presented exactly as written in the HTML file. | toolbarSettings: { items: [‘InsertCode’]} |
![]() |
Allows to print the editor content. | toolbarSettings: { items: [‘Print’]} | |
ClearAll | ![]() |
Removes all styles that have been applied to the selected text. | toolbarSettings: { items: [‘ClearAll’]} |
SourceCode | ![]() |
Rich Text Editor includes the ability for users to directly edit HTML code via “Source View”. If you made any modification in Source view directly, synchronize with Design view. | toolbarSettings: { items: [‘SourceCode’]} |
Toolbar in EJ2 TypeScript Rich text editor control
The Rich Text Editor toolbar contains a collection of tools such as bold, italic and text alignment buttons that are used to format the content. However, in most integrations, you can customize the toolbar configurations easily to suit your needs.
To create Rich Text Editor with Toolbar feature, inject the Toolbar module to the Rich Text Editor using the
RichTextEditor.Inject(Toolbar)
method.
The Rich Text Editor allows you to configure different types of toolbar using type field in toolbarSettings property. The types of toolbar are:
- Expand
- MultiRow
- Scrollable
Expand Toolbar
The default mode of the toolbar is Expand
, configured through toolbarSettings
with type: 'Expand'
. This mode hides any overflowing toolbar items in the next row, which can viewed by clicking the expand arrow.
import { RichTextEditor, Toolbar, HtmlEditor } from '@syncfusion/ej2-richtexteditor';
RichTextEditor.Inject(Toolbar, HtmlEditor);
let defaultRTE: RichTextEditor = new RichTextEditor({
height: 340,
value: ` <p>The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor that provides the best user experience to create and update the content.Users can format their content using standard toolbar commands.</p>
<p><b>Key features:</b></p>
<ul><li><p>Provides <IFRAME> and <DIV> modes</p></li>
<li><p>Capable of handling markdown editing.</p></li>
<li><p>Contains a modular library to load the necessary functionality on demand.</p></li>
<li><p>Provides a fully customizable toolbar.</p></li>
<li><p>Provides HTML view to edit the source directly for developers.</p></li>
<li><p>Supports third-party library integration.</p></li>
<li><p>Allows preview of modified content before saving it.</p></li>
<li><p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
</ul>`,
toolbarSettings: {
type: 'Expand'
}});
defaultRTE.appendTo('#defaultRTE');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='defaultRTE'>
</div>
</div>
</body>
</html>
Configuring a Multi-row Toolbar
Setting the type
as MultiRow
in toolbarSettings will arrange the toolbar items across multiple rows, displaying all configured toolbar items.
import { RichTextEditor, Toolbar, HtmlEditor } from '@syncfusion/ej2-richtexteditor';
RichTextEditor.Inject(Toolbar, HtmlEditor);
let defaultRTE: RichTextEditor = new RichTextEditor({
height: 340,
value: ` <p>The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor that provides the best user experience to create and update the content.Users can format their content using standard toolbar commands.</p>
<p><b>Key features:</b></p>
<ul><li><p>Provides <IFRAME> and <DIV> modes</p></li>
<li><p>Capable of handling markdown editing.</p></li>
<li><p>Contains a modular library to load the necessary functionality on demand.</p></li>
<li><p>Provides a fully customizable toolbar.</p></li>
<li><p>Provides HTML view to edit the source directly for developers.</p></li>
<li><p>Supports third-party library integration.</p></li>
<li><p>Allows preview of modified content before saving it.</p></li>
<li><p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
<li><p>Contains undo/redo manager.</p></li>
<li><p>Creates bulleted and numbered lists.</p></li>
</ul>`,
toolbarSettings: {
type: 'MultiRow'
}});
defaultRTE.appendTo('#defaultRTE');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='defaultRTE'>
</div>
</div>
</body>
</html>
Implementing a Scrollable Toolbar
Setting the type
to Scrollable
in toolbarSettings will display the toolbar items in a single line, enabling horizontal scrolling in the toolbar.
import { RichTextEditor, Toolbar, HtmlEditor } from '@syncfusion/ej2-richtexteditor';
RichTextEditor.Inject(Toolbar, HtmlEditor);
let defaultRTE: RichTextEditor = new RichTextEditor({
height: 340,
value: ` <p>The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor that provides the best user experience to create and update the content.Users can format their content using standard toolbar commands.</p>
<p><b>Key features:</b></p>
<ul><li><p>Provides <IFRAME> and <DIV> modes</p></li>
<li><p>Capable of handling markdown editing.</p></li>
<li><p>Contains a modular library to load the necessary functionality on demand.</p></li>
<li><p>Provides a fully customizable toolbar.</p></li>
<li><p>Provides HTML view to edit the source directly for developers.</p></li>
<li><p>Supports third-party library integration.</p></li>
<li><p>Allows preview of modified content before saving it.</p></li>
<li><p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
<li><p>Contains undo/redo manager.</p></li>
<li><p>Creates bulleted and numbered lists.</p></li>
</ul>`,
toolbarSettings: {
type: 'Scrollable'
}});
defaultRTE.appendTo('#defaultRTE');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='defaultRTE'>
</div>
</div>
</body>
</html>
Creating a Sticky Toolbar
By default, the toolbar remains fixed at the top of the Rich Text Editor when scrolling. You can customize the position of this sticky toolbar by setting the floatingToolbarOffset to adjust its offset from the top of the document.
Additionally, you can enable or disable the floating toolbar using the enableFloating property.
import { RichTextEditor, Toolbar, HtmlEditor } from '@syncfusion/ej2-richtexteditor';
import { CheckBox, ChangeEventArgs } from '@syncfusion/ej2-buttons';
RichTextEditor.Inject(Toolbar, HtmlEditor);
let defaultRTE: RichTextEditor = new RichTextEditor({
height: 340,
toolbarSettings: {
enableFloating: false
},
value: ` <p>The Rich Text Editor component is WYSIWYG ("what you see is what you get") editor that provides the best user experience to create and update the content.Users can format their content using standard toolbar commands.</p>
<p><b>Key features:</b></p>
<ul><li><p>Provides <IFRAME> and <DIV> modes</p></li>
<li><p>Capable of handling markdown editing.</p></li>
<li><p>Contains a modular library to load the necessary functionality on demand.</p></li>
<li><p>Provides a fully customizable toolbar.</p></li>
<li><p>Provides HTML view to edit the source directly for developers.</p></li>
<li><p>Supports third-party library integration.</p></li>
<li><p>Allows preview of modified content before saving it.</p></li>
<li><p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>
</ul>`});
defaultRTE.appendTo('#defaultRTE');
let float: CheckBox = new CheckBox({
// set false for enable the checked state at initial rendering
checked: false,
label: 'Enable Floating',
// bind change event
change: (args: ChangeEventArgs) => {
defaultRTE.toolbarSettings.enableFloating = (args as any).checked;
defaultRTE.dataBind();
}
});
float.appendTo('#float');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='defaultRTE'>
</div>
<input type="checkbox" id="float" checked="false">
</div>
</body>
</html>
Custom Toolbar Items
The Rich Text Editor allows you to configure your own commands to its toolbar using the toolbarSettings
property. The command can be plain text, icon, or HTML template. The order and the group can also be defined where the command should be included. Bind action to the command by getting its instance.
This sample shows how to add your own commands to the toolbar of the Rich Text Editor. The “Ω” command is added to insert special characters in the editor. By clicking the “Ω” command, it will show the special characters list, and then choose the character to be inserted in the editor.
The following code snippet illustrates custom tool with tooltip text which will be included in items
field of the toolbarSettings
property.
{
tooltipText: 'Insert Symbol',
undo: true,
click: function() {
},
template: '<button class="e-tbar-btn e-btn" tabindex="-1" id="custom_tbar" style="width:100%"><div class="e-tbar-btn-text" style="font-weight: 500;"> Ω</div></button>'
}
Click the Ω
command to show the special characters list, and then choose the character to be inserted in the editor.
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
import {
RichTextEditor,
Toolbar,
Link,
NodeSelection,
Image,
QuickToolbar,
HtmlEditor,
} from '@syncfusion/ej2-richtexteditor';
import { Dialog } from '@syncfusion/ej2-popups';
RichTextEditor.Inject(Toolbar, Link, Image, QuickToolbar, HtmlEditor);
let selection: NodeSelection = new NodeSelection();
// Initialization of Dialog
let dialog: Dialog = new Dialog({
header: 'Special Characters',
content: document.getElementById('rteSpecial_char'),
target: document.getElementById('container'),
showCloseIcon: true,
isModal: true,
visible: false,
height: 'auto',
width: '500px',
cssClass: 'e-rte-elements',
overlayClick: dialogOverlay,
buttons: [
{ buttonModel: { content: 'Insert', isPrimary: true }, click: onInsert },
{ buttonModel: { content: 'Cancel' }, click: dialogOverlay },
],
created: onCreated,
});
// Render initialized Dialog
dialog.appendTo('#customTbarDialog');
let defaultRTE: RichTextEditor = new RichTextEditor({
value: `<div style='display: block;'><p style='margin-right: 10px'>The custom command \"insert special character\" is configured as the last item of the toolbar. Click on the command and choose the special character you want to include from the popup.</p></div>`,
toolbarSettings: {
items: [
'Bold',
'Italic',
'Underline',
'|',
'Formats',
'Alignments',
'OrderedList',
'UnorderedList',
'|',
'CreateLink',
'Image',
'|',
'SourceCode',
{
tooltipText: 'Insert Symbol',
undo: true,
click: function () {
dialog.element.style.display = '';
selection = defaultRTE.formatter.editorManager.nodeSelection;
var range = selection.getRange(
defaultRTE.contentModule.getDocument()
);
selection.save(range, defaultRTE.contentModule.getDocument());
dialog.show();
},
template:
'<button class="e-tbar-btn e-btn" tabindex="-1" id="custom_tbar" style="width:100%"><div class="e-tbar-btn-text" style="font-weight: 500;"> Ω</div></button>',
},
'|',
'Undo',
'Redo',
],
},
});
defaultRTE.appendTo('#defaultRTE');
function dialogOverlay() {
let activeEle: HTMLElement = dialog.element.querySelector(
'.char_block.e-active'
);
if (activeEle) {
activeEle.classList.remove('e-active');
}
dialog.hide();
}
function onInsert() {
selection.restore();
let activeEle: HTMLElement = dialog.element.querySelector(
'.char_block.e-active'
);
if (activeEle) {
defaultRTE.executeCommand('insertText', activeEle.textContent, {
undo: true,
});
}
dialogOverlay();
}
function onCreated() {
var dialogCtn = document.getElementById('rteSpecial_char');
dialogCtn.onclick = function (e: Event) {
let target: HTMLElement = e.target as HTMLElement;
let activeEle: HTMLElement = dialog.element.querySelector(
'.char_block.e-active'
);
if (target.classList.contains('char_block')) {
target.classList.add('e-active');
if (activeEle) {
activeEle.classList.remove('e-active');
}
}
};
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' class='e-rte-custom-tbar-section'>
<div id='defaultRTE'>
</div>
<div id="customTbarDialog" style="display: none">
<div id="rteSpecial_char">
<div class="char_block" title="^">^</div>
<div class="char_block" title="_">_</div>
<div class="char_block" title="`">`</div>
<div class="char_block" title="{">{</div>
<div class="char_block" title="|">|</div>
<div class="char_block" title="}">}</div>
<div class="char_block" title="~">~</div>
<div class="char_block" title=" "> </div>
<div class="char_block" title="¡">¡</div>
<div class="char_block" title="¢">¢</div>
<div class="char_block" title="£">£</div>
<div class="char_block" title="¤">¤</div>
<div class="char_block" title="¥">¥</div>
<div class="char_block" title="₹">₹</div>
<div class="char_block" title="¦">¦</div>
<div class="char_block" title="§">§</div>
<div class="char_block" title="¨">¨</div>
<div class="char_block" title="©">©</div>
<div class="char_block" title="ª">ª</div>
<div class="char_block" title="«">«</div>
<div class="char_block" title="¬">¬</div>
<div class="char_block" title="­">­</div>
<div class="char_block" title="®">®</div>
<div class="char_block" title="¯">¯</div>
<div class="char_block" title="°">°</div>
<div class="char_block" title="±">±</div>
<div class="char_block" title="²">²</div>
<div class="char_block" title="³">³</div>
<div class="char_block" title="´">´</div>
<div class="char_block" title="µ">µ</div>
<div class="char_block" title="¶">¶</div>
<div class="char_block" title="·">·</div>
<div class="char_block" title="¸">¸</div>
<div class="char_block" title="¹">¹</div>
<div class="char_block" title="º">º</div>
<div class="char_block" title="»">»</div>
<div class="char_block" title="¼">¼</div>
<div class="char_block" title="½">½</div>
<div class="char_block" title="¾">¾</div>
<div class="char_block" title="¿">¿</div>
<div class="char_block" title="À">À</div>
<div class="char_block" title="Á">Á</div>
<div class="char_block" title="Â">Â</div>
<div class="char_block" title="Ã">Ã</div>
</div>
</div>
</div>
<style>
#special_char,
.char_block {
display: inline-block;
}
.char_block.e-active {
/* box-shadow: inset 3px 3px 7px 0px; */
outline: 1.5px solid;
}
.char_block {
width: 30px;
height: 30px;
line-height: 30px;
margin: 0 5px 5px 0;
text-align: center;
vertical-align: middle;
border: 1px solid #dddddd;
font-size: 20px;
cursor: pointer;
user-select: none;
}
#custom_tbar,
#custom_tbar div {
cursor: pointer;
}
#rteSection {
height: 500px;
}
.e-rte-quick-popup .e-rte-quick-toolbar .e-roatate-left::before {
content: '\e76e';
}
.e-rte-quick-popup .e-rte-quick-toolbar .e-roatate-right::before {
content: '\e726';
}
.e-richtexteditor textarea.e-content {
float: left;
}
.e-richtexteditor .e-rte-content {
overflow: hidden;
}
.e-rte-content .e-content.e-pre-source {
width: 100%;
}
.property-panel-content td {
width: 50%;
}
.property-panel-content td div {
padding-left: 10px;
padding-top: 10px;
}
.e-icon-btn.e-active .e-md-preview::before {
content: '\e350';
}
.e-icon-btn .e-md-preview.e-icons::before {
content: '\e345';
}
.e-icon-btn.e-active .e-md-preview::before,
#mdCustom .e-icon-btn.e-active .e-md-preview.e-icons::before {
content: '\e350';
}
#mdCustom .e-icon-btn .e-md-preview.e-icons::before {
content: '\e345';
}
#rteDialog.e-dialog .e-dlg-content {
padding: 0px 0px 5px 16px;
}
#custom_tbar .e-tbar-btn-text {
font-size: 16px;
}
.e-bigger #custom_tbar .e-tbar-btn-text {
font-size: 18px;
}
@media (min-width: 320px) and (max-width: 480px) {
.fabric.e-bigger #rteDialog {
min-width: 281px;
}
.fabric #rteDialog {
min-width: 241px;
}
.bootstrap.e-bigger #rteDialog,
.bootstrap #rteDialog {
min-width: 223px;
}
.highcontrast.e-bigger #rteDialog {
min-width: 283px;
}
.highcontrast #rteDialog {
min-width: 243px;
}
.material #rteDialog {
min-width: 224px;
}
.material.e-bigger #rteDialog {
min-width: 236px;
}
}
</style>
</body>
</html>
When rendering any control for the custom toolbar, like a dropdown, the focus may be lost, causing it to render outside the Rich Text Editor and triggering a blur event. This can interfere with proper functionalities like cursor focus. To prevent this issue, it is recommended to assign the
e-rte-elements
class to the control rendered in the custom toolbar.
Quick inline toolbar
Quick commands are opened as context-menu on clicking the corresponding element. The commands must be passed as string collection to image, text, and link attributes of the quickToolbarSettings property.
Target Element | Default Quick Toolbar items |
---|---|
image | ‘Replace’, ‘Align’, ‘Caption’, ‘Remove’, ‘InsertLink’, ‘Display’, ‘AltText’,’Dimension’. |
link | ‘Open’, ‘Edit’, ‘UnLink’. |
text | null (Any toolbar items in the Rich Text Editor can be configured here). |
table | ‘TableHeader’, ‘TableRows’, ‘TableColumns’, ‘BackgroundColor’, ‘TableRemove’, ‘Alignments’, ‘TableCellVerticalAlign’, ‘Styles’. |
Custom tool can be added to the corresponding quick toolbar, using quickToolbarSettings property.
The following sample demonstrates the option to insert the image to the Rich Text Editor content as well as option to rotate the image through the quick toolbar. The image rotation functionalities have been achieved through the toolbarClick event.
import { RichTextEditor, Toolbar, Link, Image, HtmlEditor, QuickToolbar } from '@syncfusion/ej2-richtexteditor';
RichTextEditor.Inject(Toolbar, Link, Image, HtmlEditor, QuickToolbar);
let defaultRTE: RichTextEditor = new RichTextEditor({
height: 340,
quickToolbarSettings: {
image: [
'Replace', 'Align', 'Caption', 'Remove', 'InsertLink', 'OpenImageLink', '-',
'EditImageLink', 'RemoveImageLink', 'Display', 'AltText', 'Dimension'
]
},
toolbarSettings: {
items: ['Bold', 'Italic', 'Underline', 'StrikeThrough',
'FontName', 'FontSize', 'FontColor', 'BackgroundColor',
'LowerCase', 'UpperCase', '|',
'Formats', 'Alignments', 'OrderedList', 'UnorderedList',
'Outdent', 'Indent', '|',
'CreateLink', 'Image', '|', 'ClearFormat', 'Print',
'SourceCode', 'FullScreen', '|', 'Undo', 'Redo']
},
value: `<p>The Syncfudion Rich Text Editor, a WYSIWYG (what you see is what you get) editor, is a user interface that allows you to create, edit, and format rich text content. You can try out a demo of this editor here.</p><p><b>Key features:</b></p><ul><li><p>Provides <IFRAME> and <DIV> modes.</p></li><li><p>Bulleted and numbered lists.</p></li><li><p>Handles images, hyperlinks, videos, hyperlinks, uploads, etc.</p></li><li><p>Contains undo/redo manager. </p></li></ul><div style='display: inline-block; width: 60%; vertical-align: top; cursor: auto;'><img alt='Sky with sun' src='https://cdn.syncfusion.com/ej2/richtexteditor-resources/RTE-Overview.png' width='309' style='min-width: 10px; min-height: 10px; width: 309px; height: 174px;' class='e-rte-image e-imginline e-rte-drag-image' height='174' /></div>`,
});
defaultRTE.appendTo('#defaultRTE');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='defaultRTE'></div>
</div>
</body>
</html>
Rich Text Editor features are segregated into individual feature-wise modules. To use quick toolbar, inject the quick toolbar module using the
RichTextEditor.Inject(Image, Link)
.