How to Integrate Syncfusion React Mention Component with Rich Text Editor
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
How to Integrate Syncfusion React Mention Component with Rich Text Editor

How to Integrate Syncfusion React Mention Component with Rich Text Editor

The Syncfusion React Rich Text Editor (RTE) is a feature-rich WYSIWYG HTML editor. It is widely used to create blogs, forum posts, notes, support tickets (incidents), comment sections, messaging applications, and more. The control provides an efficient UI for a better editing experience on mobile devices. It has a variety of tools to edit and format rich content and return valid HTML markup or Markdown (MD) content. It allows users to insert images, links, tables, and lists with modular architectures.

From 2022 Volume 3 onward, the React Rich Text Editor allows users to easily integrate our new React Mention component to display a suggestion list of items that users can select or tag. When the user types the @ character in the editor, the suggestion list will appear, and the user can select or tag a value from it.

In this blog, we will see the procedure to integrate the React Mention component with the Rich Text Editor.

Getting started

Before getting started, please refer to the documentation for the Syncfusion React Rich Text Editor and Mention components to familiarize yourself with them.

Then, follow these steps to integrate the React Mention component with the Rich Text Editor.

Step 1:  Create a new React application.

First, install the create-react-app npm package using the following command in the desired location.

npx create-react-app my-app

Then, refer to the Getting Started with React Apps documentation to create a React app using the npm and yarn commands.

Step 2: Add the Syncfusion packages.

The npm public registry lists all the currently available Essential JS 2 packages. Install the React Rich Text Editor and Mention components with the following commands.

npm install @syncfusion/ej2-react-richtexteditor –save-dev
npm install @syncfusion/ej2-react-dropdowns –save-dev

Step 3: Add the CSS reference for the Syncfusion React Rich Text Editor and Mention components.

Now, add the following CSS files as references for the Syncfusion React Rich Text Editor and Mention components in the src/App.css file. These files are available in the ../node_modules/@syncfusion package folder.

@import '../node_modules/@syncfusion/ej2-base/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-icons/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/bootstrap5.css';
@import '../node_modules/@syncfusion/ej2-react-richtexteditor/styles/bootstrap5.css';
@import "../node_modules/@syncfusion/ej2-react-dropdowns/styles/bootstrap5.css";

Step 4: Add the Syncfusion React Rich Text Editor to your application.

Now, place the following code in the src/App.js file to add the Syncfusion React Rich Text Editor component.

import { HtmlEditor, Image, Inject, Link, QuickToolbar, RichTextEditorComponent, Toolbar } from '@syncfusion/ej2-react-richtexteditor';
import * as React from 'react';
import './App.css';
 
function App() {
 
 var actionBegineHandler = function(args){
  if (args.requestType === 'EnterAction') {
    args.cancel = true;
  }
 }
 return (
 <div className="App">
  <div className='control-section' id="rte">
   <div className='rte-control-section'>
    <RichTextEditorComponent id="mention_integration" placeholder="Type @ and tag the name"  actionBegin={actionBegineHandler.bind(this)}  >
     <p>Hello <span contentEditable={false} className='e-mention-chip'><a title="maria@gmail.com">@Maria</a></span></p>
     <p>Welcome to the mention integration with rich text editor demo. Type the <code>@</code> character and tag a user from the suggestion list. </p>
     <Inject services={[HtmlEditor, Toolbar, Image, Link, QuickToolbar]} />
    </RichTextEditorComponent>
   </div>
  </div>
 </div>
 );
}
 
export default App;

Step 5: Integrate the React Mention component with the Rich Text Editor.

  1. Add the React Mention component in the src/App.js file and set the Rich Text Editor’s editable element (#{RichTextEditor component ID}_integration_rte-edit-view”) to the Mention component’s target.
  2. Now, place the following code in the src/App.js file to integrate the Mention component with the Rich Text Editor. We are going to bind an employee data source to the Mention component. We use the itemTemplate property to customize the suggestion list items and the displayTemplate property to customize the selected value from the suggestion list.
    import { HtmlEditor, Image, Inject, Link, QuickToolbar, RichTextEditorComponent, Toolbar } from '@syncfusion/ej2-react-richtexteditor';
    import { MentionComponent } from '@syncfusion/ej2-react-dropdowns';
    import * as React from 'react';
    import './App.css';
     
    function App() {
     var data = [
      { Name: "Selma Rose", Status: "active", Eimg: "2", EmailId: "selma@gmail.com" },
      { Name: "Maria", Status: "active", Eimg: "1", EmailId: "maria@gmail.com" },
      { Name: "Russo Kay", Status: "busy", Eimg: "8", EmailId: "russo@gmail.com" },
      { Name: "Camden Kate", Status: "active", Eimg: "9", EmailId: "camden@gmail.com" },
      { Name: "Robert", Status: "busy", Eimg: "dp", EmailId: "robert@gmail.com" },
      { Name: "Garth", Status: "active", Eimg: "7", EmailId: "garth@gmail.com" },
      { Name: "Andrew James", Status: "away", Eimg: "pic04", EmailId: "noah@gmail.com" },
      { Name: "Olivia", Status: "busy", Eimg: "5", EmailId: "olivia@gmail.com" },
      { Name: "Sophia", Status: "away", Eimg: "6", EmailId: "sophia@gmail.com" },
      { Name: "Margaret", Status: "active", Eimg: "3", EmailId: "margaret@gmail.com" },
      { Name: "Ursula Ann", Status: "active", Eimg: "dp", EmailId: "ursula@gmail.com" },
      { Name: "Laura Grace", Status: "away", Eimg: "4", EmailId: "laura@gmail.com" },
      { Name: "Albert", Status: "active", Eimg: "pic03", EmailId: "albert@gmail.com" },
      { Name: "William", Status: "away", Eimg: "10", EmailId: "william@gmail.com" }
     ];
     var fieldsData = { text: 'Name' };
     
     var itemTemplate = function(data) {
      return (
       <table>
        <tbody>
         <tr>
          <td>
           <div id="mention-TemplateList">
            <img className="mentionEmpImage" src={"./images/" + data.Eimg +".png"} />
            <span className={"e-badge e-badge-success e-badge-overlap e-badge-dot e-badge-bottom"+ data.Status}></span>
           </div>
          </td>
          <td className="mentionNameList">
           <span className="person">{data.Name}</span>
           <span className="email">{data.EmailId}</span>
          </td>
         </tr>
        </tbody>
       </table>
      );
     }
     var displayTemplate= function(data) {
      return (
       <React.Fragment><a title={data.EmailId}>@{data.Name}</a></React.Fragment>
      );
     }
     var actionBegineHandler = function(args){
      if (args.requestType === 'EnterAction') {
       args.cancel = true;
      }
    }
    return (
     <div className="App">
      <div className='control-section' id="rte">
       <div className='rte-control-section'>
        <RichTextEditorComponent id="mention_integration" placeholder="Type @ and tag the name"  actionBegin={actionBegineHandler.bind(this)}  >
         <p>Hello <span contentEditable={false} className='e-mention-chip'><a title="maria@gmail.com">@Maria</a></span></p>
         <p>Welcome to the mention integration with rich text editor demo. Type the <code>@</code> character and tag a user from the suggestion list. </p>
         <Inject services={[HtmlEditor, Toolbar, Image, Link, QuickToolbar]} />
        </RichTextEditorComponent>
       </div>
      </div>
      <MentionComponent id="mentionEditor" target="#mention_integration_rte-edit-view" suggestionCount={8} showMentionChar={false}  allowSpaces={true} dataSource={data} fields={fieldsData}
                        popupWidth="250px" popupHeight="200px" itemTemplate={itemTemplate} displayTemplate={displayTemplate.bind(this)}></MentionComponent>
     </div>
    );
    }
     
    export default App;
  3. Then, add the following styles in the src/App.css file to customize the Mention suggestion list items and select a value from the suggestion list.
    #mention-TemplateList {
      position: relative;
      display: inline-block;
      padding: 2px;
    }
    .mentionNameList .person, .mentionNameList .email {
      display: block;
      line-height: 20px;
      text-indent: 5px;
    }
    .mentionNameList .person {
      font-size: 16px;
    }
    .mentionEmpImage {
      display: inline-block;
      width: 46px;
      height: 46px;
      padding: 3px;
      border-radius: 25px;
    }
    #mention-TemplateList .e-badge-success {
      left: 76%;
      bottom: 6px;
      top: auto;
    }
    #mention_integration_rte-edit-view_popup .e-dropdownbase .e-list-item {
      line-height: 8px;
    }
    #mention-TemplateList .e-badge-success {
      background-color: #4d841d;
      color: #fff;
    }
    #mention-TemplateList .e-badge-success.away {
      background-color: #fedd2d;
      color: #fff;
    }
    #mention-TemplateList .e-badge-success.busy {
      background-color: #de1a1a;
      color: #fff;
    }
    #mention-TemplateList .e-badge.e-badge-dot {
      height: 10px;
      width: 10px;
    }
    #mention_integration .e-mention-chip {
      cursor: pointer;
    }

    After executing the above code example, we will get output like the following GIF image.

    React Mention Component Integration with Rich Text Editor Control
    React Mention Component Integration with Rich Text Editor Control

GitHub reference

For more details, check out the React Mention component integration with React Rich Text Editor component GitHub demo.

Conclusion

Thanks for reading! I hope now you have a clear idea of how to integrate the Syncfusion React Mention component with the Rich Text Editor. This support is available in the 2022 Volume 3 release. We look forward to hearing your thoughts on this integration in the comments section below.

Check out our Release Notes and What’s New pages to see the other updates in this Volume 3 release.

Also, you can reach us through our support forumssupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed