Table of Contents

Class RadzenHtmlEditor

Namespace
Radzen.Blazor
Assembly
Radzen.Blazor.dll

A component which edits HTML content. Provides built-in upload capabilities.

public class RadzenHtmlEditor : FormComponent<string>, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, IRadzenFormComponent
Inheritance
RadzenHtmlEditor
Implements
Inherited Members

Examples

<RadzenHtmlEditor @bind-Value=@html />
@code {
  string html = "@lt;strong>Hello</strong> world!";
}

Constructors

RadzenHtmlEditor()

public RadzenHtmlEditor()

Properties

ChildContent

Gets or sets the child content.

[Parameter]
public RenderFragment ChildContent { get; set; }

Property Value

RenderFragment

The child content.

Execute

A callback that will be invoked when the user executes a command of the editor (e.g. by clicking one of the tools).

[Parameter]
public EventCallback<HtmlEditorExecuteEventArgs> Execute { get; set; }

Property Value

EventCallback<HtmlEditorExecuteEventArgs>

Examples

<RadzenHtmlEditor Execute=@OnExecute>
  <RadzenHtmlEditorCustomTool CommandName="InsertToday" Icon="today" Title="Insert today" />
</RadzenHtmlEditor>
@code {
  string html = "@lt;strong>Hello</strong> world!";
  async Task OnExecute(HtmlEditorExecuteEventArgs args)
  {
    if (args.CommandName == "InsertToday")
    {
      await args.Editor.ExecuteCommandAsync(HtmlEditorCommands.InsertHtml, DateTime.Today.ToLongDateString());
    }
 }

Input

Gets or sets the input.

[Parameter]
public EventCallback<string> Input { get; set; }

Property Value

EventCallback<string>

The input.

Mode

Gets or sets the mode of the editor.

[Parameter]
public HtmlEditorMode Mode { get; set; }

Property Value

HtmlEditorMode

Paste

A callback that will be invoked when the user pastes content in the editor. Commonly used to filter unwanted HTML.

[Parameter]
public EventCallback<HtmlEditorPasteEventArgs> Paste { get; set; }

Property Value

EventCallback<HtmlEditorPasteEventArgs>

Examples

<RadzenHtmlEditor @bind-Value=@html Paste=@OnPaste />
@code {
  string html = "@lt;strong>Hello</strong> world!";
  void OnPaste(HtmlEditorPasteEventArgs args)
  {
    // Set args.Html to filter unwanted tags.
    args.Html = args.Html.Replace("<br>", "");
  }

ShowToolbar

Specifies whether to show the toolbar. Set it to false to hide the toolbar. Default value is true.

[Parameter]
public bool ShowToolbar { get; set; }

Property Value

bool

UploadError

A callback that will be invoked when there is an error during upload.

[Parameter]
public EventCallback<UploadErrorEventArgs> UploadError { get; set; }

Property Value

EventCallback<UploadErrorEventArgs>

UploadHeaders

Specifies custom headers that will be submit during uploads.

[Parameter]
public IDictionary<string, string> UploadHeaders { get; set; }

Property Value

IDictionary<string, string>

UploadUrl

Specifies the URL to which RadzenHtmlEditor will submit files.

[Parameter]
public string UploadUrl { get; set; }

Property Value

string

Methods

BuildRenderTree(RenderTreeBuilder)

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

Dispose()

public override void Dispose()

ExecuteCommandAsync(string, string)

Executes the requested command with the provided value. Check HtmlEditorCommands for the list of supported commands.

public Task ExecuteCommandAsync(string name, string value = null)

Parameters

name string

The name.

value string

The value.

Returns

Task

ExecuteShortcutAsync(string)

Executes the action associated with the specified shortcut. Used internally by RadzenHtmlEditor.

[JSInvokable("ExecuteShortcutAsync")]
public Task ExecuteShortcutAsync(string shortcut)

Parameters

shortcut string

Returns

Task

FocusAsync()

Focuses the editor.

public override ValueTask FocusAsync()

Returns

ValueTask

GetComponentCssClass()

protected override string GetComponentCssClass()

Returns

string

GetHeaders()

Invoked by interop during uploads. Provides the custom headers.

[JSInvokable("GetHeaders")]
public IDictionary<string, string> GetHeaders()

Returns

IDictionary<string, string>

GetMode()

Returns the current mode of the editor.

public HtmlEditorMode GetMode()

Returns

HtmlEditorMode

OnAfterRenderAsync(bool)

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

OnChange(string)

Invoked via interop when the value of RadzenHtmlEditor changes.

[JSInvokable]
public void OnChange(string html)

Parameters

html string

The HTML.

OnError(string)

Called on upload error.

[JSInvokable("OnError")]
public Task OnError(string error)

Parameters

error string

The error.

Returns

Task

OnInitialized()

protected override void OnInitialized()

OnPaste(string)

Invoked via interop when the user pastes content in RadzenHtmlEditor. Invokes Paste.

[JSInvokable]
public Task<string> OnPaste(string html)

Parameters

html string

The HTML.

Returns

Task<string>

OnSelectionChange()

Invoked by interop when the RadzenHtmlEditor selection changes.

[JSInvokable]
public Task OnSelectionChange()

Returns

Task

RegisterShortcut(string, Func<Task>)

Registers a shortcut for the specified action.

public void RegisterShortcut(string key, Func<Task> action)

Parameters

key string

The shortcut. Can be combination of keys such as CTRL+B.

action Func<Task>

The action to execute.

RestoreSelectionAsync()

Restores the last saved selection.

public Task RestoreSelectionAsync()

Returns

Task

SaveSelectionAsync()

Saves the current selection. RadzenHtmlEditor will lose its selection when it loses focus. Use this method to persist the current selection.

public Task SaveSelectionAsync()

Returns

Task

SetParametersAsync(ParameterView)

public override Task SetParametersAsync(ParameterView parameters)

Parameters

parameters ParameterView

Returns

Task

UnregisterShortcut(string)

Unregisters the specified shortcut.

public void UnregisterShortcut(string key)

Parameters

key string