<SfRichTextEditor Placeholder="Enter Some Content">
<RichTextEditorToolbarSettings Items="@Tools" />
<RichTextEditorFontFamily Items="@FontFamilyItems" Default="Verdana" />
<RichTextEditorFontSize Items="@FontSizeItems" Default="16pt"></RichTextEditorFontSize>
</SfRichTextEditor>
<style>
.e-richtexteditor .e-rte-content .e-content,
.e-richtexteditor .e-source-content .e-content {
font-size: 16pt;
font-family: Verdana;
}
</style>
@code {
private List<DropDownItemModel> FontSizeItems = new List<DropDownItemModel>()
{
//Newly added font size.
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "16 pt", Value = "16pt" },
//Default Font Size in Rich Text Editor.
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "8 pt", Value = "8pt" },
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "10 pt", Value = "10pt" },
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "12 pt", Value = "12pt" },
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "14 pt", Value = "14pt" },
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "18 pt", Value = "18pt" },
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "24 pt", Value = "24pt" },
new DropDownItemModel() { Command = "Font", SubCommand = "FontSize", Text = "36 pt", Value = "36pt" }
};
private List<DropDownItemModel> FontFamilyItems = new List<DropDownItemModel>()
{
//Newly added font family.
new DropDownItemModel() { CssClass = "e-roboto-ui", Command = "Font", SubCommand = "FontName", Text = "Roboto", Value = "Roboto" },
//Default Font family in Rich Text Editor.
new DropDownItemModel() { CssClass = "e-segoe-ui", Command = "Font", SubCommand = "FontName", Text = "Segoe UI", Value = "Segoe UI" },
new DropDownItemModel() { CssClass = "e-arial", Command = "Font", SubCommand = "FontName", Text = "Arial", Value = "Arial,Helvetica,sans-serif" },
new DropDownItemModel() { CssClass = "e-georgia", Command = "Font", SubCommand = "FontName", Text = "Georgia", Value = "Georgia,serif" },
new DropDownItemModel() { CssClass = "e-impact", Command = "Font", SubCommand = "FontName", Text = "Impact", Value = "Impact,Charcoal,sans-serif" },
new DropDownItemModel() { CssClass = "e-tahoma", Command = "Font", SubCommand = "FontName", Text = "Tahoma", Value = "Tahoma,Geneva,sans-serif" },
new DropDownItemModel() { CssClass = "e-times-new-roman", Command = "Font", SubCommand = "FontName", Text = "Times New Roman", Value = "Times New Roman,Times,serif" },
new DropDownItemModel() { CssClass = "e-verdana", Command = "Font", SubCommand = "FontName", Text = "Verdana", Value = "Verdana,Geneva,sans-serif" }
};
. . .
} |
<head>
. . .
</head> |
Hi,
I'm experiencing also a initial value problem.
The inital p tag doesn't contain the default font size and font family.
can be seen in my demo app.
https://github.com/alisio92/TextEditorDemo
video showcase in attachment.
thanks
Attachment: demo_61603df3.zip
Hi, please note this doesn't quite match what is stated in the documentation:
https://blazor.syncfusion.com/documentation/rich-text-editor/how-to/default-font
The sample listed above works. What's stated in the documentation does not.
Thanks.
Dear Vinitha Jeyakumar
Continuing on the question from Alisio Putman, I have edited your sample to reconstruct the issue.
Following the documentation as stated on
https://blazor.syncfusion.com/documentation/rich-text-editor/how-to/default-font, to set the default font, you have to configure the RTE and add a style tag to the page to set the context class
<RichTextEditorFontFamily Default="Impact" Items="@FontFamilyItems" />
<RichTextEditorFontSize Default="36 pt" />
<style>
.customClass .e-rte-content .e-content {
/* to get the desired font on intially*/
font-family: Impact,Charcoal,sans-serif;
font-size: 36pt;
}
</style>
When typing new text in an empty RTE with a default font, the typed text will correctly be shown in the default font. However, when retrieving the value of the RTE, with two-way binding for example, you will get html and text without the default font styling.
Using this value on a different page, a dynamic html component, in an email, in a RTE with a different class... will result in plain text without the set default font as styling.
I assume this:
This is an issue when you save the value to the database and reload it in a RTE with a different default font. The result will be a styling with that RTE's default font, instead of the default font you saved the text in originally, as the styling is not passed with the value of the RTE
Attachment: RTE_Server1169589029_edit_b275d99a.zip
<SfRichTextEditor CssClass="customClass" @bind-Value="@_myTextFromRTE"> <RichTextEditorToolbarSettings Items="@Tools" /> <RichTextEditorFontFamily Default="Impact" Items="@FontFamilyItems" /> <RichTextEditorFontSize Default="36 pt" /> </SfRichTextEditor> <p> <button type="button" @onclick="@RenderComponent"> Render above text as actual html </button> </p> <SfRichTextEditor CssClass="classWithoutDefaults" @bind-Value="@dynamicContent" Readonly="true"> <RichTextEditorToolbarSettings Items="@Tools" /> <RichTextEditorFontFamily Default="Impact" Items="@FontFamilyItems" /> <RichTextEditorFontSize Default="36 pt" /> </SfRichTextEditor> <style> .customClass .e-rte-content .e-content { /* to get the desired font on intially*/ font-family: Impact,Charcoal,sans-serif; font-size: 36pt; } .classWithoutDefaults .e-rte-content .e-content { /* to get the desired font on intially*/ font-family: initial; font-size: initial; } </style> @code{ public string RTEContent { get; set; } private string dynamicContent = ""; private string _myTextFromRTE = ""; private async Task RenderComponent() { RTEContent = "<div style='font-family: Impact; font-size:36pt;'>" + _myTextFromRTE + "</div>"; dynamicContent = RTEContent; } |