Integrating the Angular Rich Text Editor with Tailwind CSS
18 Nov 20188 minutes to read
When combining the Rich Text Editor with Tailwind CSS, you may encounter unintended style conflicts. Tailwind’s Preflight, a base reset layer, can override default element styles used by the Rich Text Editor, leading to formatting inconsistencies. This guide documents the integration process, offering solutions to maintain design integrity and functionality. In the Rich Text Editor, it affects ordered and unordered lists, which are unformatted by default, with no bullets or numbers.
To resolve this issue and ensure that the list styles are correctly applied, you can copy and use the following styles directly in your application.
.e-rte-content li {
margin-bottom: 10px !important;
padding: unset !important;
}
.e-rte-content ul {
list-style-type: disc !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ol {
list-style-type: decimal !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ul[style*="list-style-type: circle"]{
list-style-type: circle !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ul[style*="list-style-type: square"]{
list-style-type: square !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ol[style*="list-style-type: upper-alpha"]{
list-style-type: upper-alpha !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ol[style*="list-style-type: lower-alpha"]{
list-style-type: lower-alpha !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ol[style*="list-style-type: upper-roman"]{
list-style-type: upper-roman !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ol[style*="list-style-type: lower-roman"]{
list-style-type: lower-roman !important;
padding: unset !important;
margin-left: 40px;
}
.e-rte-content ol[style*="list-style-type: lower-greek"]{
list-style-type: lower-greek !important;
padding: unset !important;
margin-left: 40px;
}import { RichTextEditorModule } from '@syncfusion/ej2-angular-richtexteditor'
import { Component, ViewChild } from '@angular/core';
import { RichTextEditorComponent, ToolbarService, HtmlEditorService, PasteCleanupService, ImageService, QuickToolbarService, LinkService } from '@syncfusion/ej2-angular-richtexteditor';
@Component({
imports: [RichTextEditorModule],
standalone: true,
selector: 'app-root',
template: `<ejs-richtexteditor #defaultRTE id='defaultRTE' [(value)]='value'></ejs-richtexteditor>`,
providers: [ToolbarService, HtmlEditorService, ImageService, PasteCleanupService, QuickToolbarService, LinkService]
})
export class AppComponent {
@ViewChild('defaultRTE') rteObj: RichTextEditorComponent | undefined;
public value: string = "<p>The Rich Text Editor component is a 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 a 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>";
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Configuring Tailwind CSS Preflight Styles with the Iframe editor
Tailwind CSS includes a “Preflight” feature, an opinionated set of base styles that normalize and reset default browser styles. When working with an Iframe editor, Preflight can sometimes conflict with or unintentionally style the iframe content. Here’s how to fine-tune Tailwind’s Preflight behavior in such scenarios with the CSS styles,
body.e-content li {
margin-bottom: 10px !important;
padding: unset !important;
}
body.e-content ul {
list-style-type: disc !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ol {
list-style-type: decimal !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ul[style*="list-style-type: circle"]{
list-style-type: circle !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ul[style*="list-style-type: square"]{
list-style-type: square !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ol[style*="list-style-type: lower-greek"]{
list-style-type: lower-greek !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ol[style*="list-style-type: upper-alpha"]{
list-style-type: upper-alpha !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ol[style*="list-style-type: lower-alpha"]{
list-style-type: lower-alpha !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ol[style*="list-style-type: upper-roman"]{
list-style-type: upper-roman !important;
padding: unset !important;
margin-left: 40px;
}
body.e-content ol[style*="list-style-type: lower-roman"]{
list-style-type: lower-roman !important;
padding: unset !important;
margin-left: 40px;
}import { RichTextEditorModule, IFrameSettingsModel, } from '@syncfusion/ej2-angular-richtexteditor'
import { Component, ViewChild } from '@angular/core';
import { RichTextEditorComponent, ToolbarService, HtmlEditorService, PasteCleanupService, ImageService, QuickToolbarService, LinkService } from '@syncfusion/ej2-angular-richtexteditor';
@Component({
imports: [RichTextEditorModule],
standalone: true,
selector: 'app-root',
template: `<ejs-richtexteditor #defaultRTE id='defaultRTE' [iframeSettings]='iframe' [(value)]='value'></ejs-richtexteditor>`,
providers: [ToolbarService, HtmlEditorService, ImageService, PasteCleanupService, QuickToolbarService, LinkService]
})
export class AppComponent {
@ViewChild('defaultRTE') rteObj: RichTextEditorComponent | undefined;
public iframe: IFrameSettingsModel = { enable: true };
public value: string = "<p>The Rich Text Editor component is a 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 a 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>";
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));