# RadzenHtmlEditor Class

A rich text HTML editor component with WYSIWYG editing, formatting toolbar, image upload, and custom tool support. RadzenHtmlEditor provides a full-featured editor for creating and editing formatted content with a Microsoft Word-like interface. Allows users to create rich formatted content without knowing HTML. Features WYSIWYG (what-you-see-is-what-you-get) visual editing interface, formatting tools (bold, italic, underline, font selection, colors, alignment, lists, links, images), built-in image upload with configurable upload URL, custom toolbar buttons via RadzenHtmlEditorCustomTool, toggle between visual editing and HTML source code view, paste filtering to remove unwanted HTML when pasting from other sources, and programmatic execution of formatting commands via ExecuteCommandAsync(). The Value property contains HTML markup. Use UploadUrl to configure where images are uploaded. Add custom tools for domain-specific functionality like inserting templates or special content.

Namespace: [Radzen.Blazor](https://blazor.radzen.com/docs/api/Radzen.Blazor.md)

Assembly: Radzen.Blazor.dll

## Inheritance

- Object
- ComponentBase
- [RadzenComponent](https://blazor.radzen.com/docs/api/Radzen.RadzenComponent.md)
- [FormComponent<string>](https://blazor.radzen.com/docs/api/Radzen.FormComponent-1.md)
- RadzenHtmlEditor

## Implements

- IComponent
- IHandleEvent
- IHandleAfterRender
- [IRadzenFormComponent](https://blazor.radzen.com/docs/api/Radzen.IRadzenFormComponent.md)

## Syntax

```csharp
public class RadzenHtmlEditor : FormComponent<string>, IComponent, IHandleEvent, IHandleAfterRender, IRadzenFormComponent
```

## Examples

Basic HTML editor:

```razor
<RadzenHtmlEditor @bind-Value=@htmlContent Style="height: 400px;" />
@code {
    string htmlContent = "<p>Enter content here...</p>";
}
```

Editor with image upload:

```razor
<RadzenHtmlEditor @bind-Value=@content UploadUrl="api/upload/image" UploadHeaders=@uploadHeaders>
    <RadzenHtmlEditorBold />
    <RadzenHtmlEditorItalic />
    <RadzenHtmlEditorUnderline />
    <RadzenHtmlEditorSeparator />
    <RadzenHtmlEditorImage />
</RadzenHtmlEditor>
```

Editor with custom tool:

```razor
<RadzenHtmlEditor @bind-Value=@html Execute=@OnExecute>
    <RadzenHtmlEditorCustomTool CommandName="InsertDate" Icon="calendar_today" Title="Insert Current Date" />
</RadzenHtmlEditor>
@code {
    async Task OnExecute(HtmlEditorExecuteEventArgs args)
    {
        if (args.CommandName == "InsertDate")
        {
            await args.Editor.ExecuteCommandAsync(HtmlEditorCommands.InsertHtml, DateTime.Today.ToLongDateString());
        }
    }
}
```

## Constructors

| Constructor | Description |
|-------------|-------------|
| `public RadzenHtmlEditor()` | A rich text HTML editor component with WYSIWYG editing, formatting toolbar, image upload, and custom tool support. RadzenHtmlEditor provides a full-featured editor for creating and editing formatted content with a Microsoft Word-like interface. Allows users to create rich formatted content without knowing HTML. Features WYSIWYG (what-you-see-is-what-you-get) visual editing interface, formatting tools (bold, italic, underline, font selection, colors, alignment, lists, links, images), built-in image upload with configurable upload URL, custom toolbar buttons via RadzenHtmlEditorCustomTool, toggle between visual editing and HTML source code view, paste filtering to remove unwanted HTML when pasting from other sources, and programmatic execution of formatting commands via ExecuteCommandAsync(). The Value property contains HTML markup. Use UploadUrl to configure where images are uploaded. Add custom tools for domain-specific functionality like inserting templates or special content. |

## Properties

| Property | Type | Description |
|------|------|-------------|
| ChildContent | `RenderFragment` | Gets or sets the child content. |
| Execute | `EventCallback<HtmlEditorExecuteEventArgs>` | A callback that will be invoked when the user executes a command of the editor (e.g. by clicking one of the tools). |
| Immediate | `bool` | Gets or sets a value indicating whether the source editor should update the value on every keystroke. When true, typing in the HTML source textarea invokes change immediately instead of on blur. Set to false by default. |
| Input | `EventCallback<string>` | Gets or sets the input. |
| Mode | [`HtmlEditorMode`](https://blazor.radzen.com/docs/api/Radzen.HtmlEditorMode.md) | Gets or sets the editor mode determining whether users see the visual editor or HTML source code. Design mode shows WYSIWYG editing, Source mode shows raw HTML for advanced users. |
| Paste | `EventCallback<HtmlEditorPasteEventArgs>` | A callback that will be invoked when the user pastes content in the editor. Commonly used to filter unwanted HTML. |
| ShowToolbar | `bool` | Gets or sets whether to display the formatting toolbar above the editor. When false, hides the toolbar but editing is still possible. Useful for read-only or simplified views. |
| State | [`RadzenHtmlEditorCommandState`](https://blazor.radzen.com/docs/api/Radzen.Blazor.RadzenHtmlEditorCommandState.md) | Represents the current state of the toolbar commands and other functionalities within the RadzenHtmlEditor component. Updated dynamically based on user actions or programmatically invoked commands. |
| TableSelection | [`HtmlEditorTableSelection`](https://blazor.radzen.com/docs/api/Radzen.HtmlEditorTableSelection.md) | Gets the current table selection state. |
| TableStrings | [`HtmlEditorTableStrings`](https://blazor.radzen.com/docs/api/Radzen.Blazor.HtmlEditorTableStrings.md) | Gets or sets localizable strings used by the table tools. |
| UploadComplete | `EventCallback<UploadCompleteEventArgs>` | Gets or sets the callback which when a file is uploaded. |
| UploadError | `EventCallback<UploadErrorEventArgs>` | A callback that will be invoked when there is an error during upload. |
| UploadHeaders | `IDictionary<string, string>` | Specifies custom headers that will be submit during uploads. |
| UploadUrl | `string` | Specifies the URL to which RadzenHtmlEditor will submit files. |

### Execute example

```razor
<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());
    }
 }
```

### Paste example

```razor
<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>", "");
  }
```

## Methods

| Method | Returns | Description |
|------|---------|-------------|
| `BuildRenderTree(Rendering.RenderTreeBuilder __builder)` | `void` |  |
| `Dispose()` | `void` |  |
| `ExecuteCommandAsync(string name, string value)` | `Task` | Executes the requested command with the provided value. Check [HtmlEditorCommands](https://blazor.radzen.com/docs/api/Radzen.HtmlEditorCommands.md) for the list of supported commands. Parameters: `name`: The name. `value`: The value. |
| `ExecuteShortcutAsync(string shortcut)` | `Task` | Executes the action associated with the specified shortcut. Used internally by RadzenHtmlEditor. |
| `ExecuteTableCommandAsync(string name, HtmlEditorTableCommandArgs value)` | `Task` | Executes a table command for the currently selected table. Parameters: `name`: The table command name. `value`: Optional table command arguments. |
| `FocusAsync()` | `ValueTask` | Focuses the editor. |
| `GetComponentCssClass()` | `string` |  |
| `GetHeaders()` | `IDictionary<string, string>` | Invoked by interop during uploads. Provides the custom headers. |
| `GetMode()` | [`HtmlEditorMode`](https://blazor.radzen.com/docs/api/Radzen.HtmlEditorMode.md) | Returns the current mode of the editor. |
| `GetSelectionAttributes(string selector, String[] attributes)` | `ValueTask<T>` | Retrieves the specified attributes of a selection within the content editable area. Parameters: `selector`: The CSS selector used to target the element. `attributes`: An array of attribute names to retrieve. Returns: A task that represents the asynchronous operation, returning the attributes as an object of type T. |
| `GetTableSelectionAsync()` | `ValueTask<HtmlEditorTableSelection>` | Gets information about the currently selected table, if any. |
| `OnAfterRenderAsync(bool firstRender)` | `Task` |  |
| `OnChange(string html)` | `void` | Invoked via interop when the value of RadzenHtmlEditor changes. Parameters: `html`: The HTML. |
| `OnContextMenu(double clientX, double clientY)` | `Task` | Invoked by interop when the user opens the context menu inside the editor. Parameters: `clientX`: The horizontal mouse position. `clientY`: The vertical mouse position. |
| `OnError(string error)` | `Task` | Called on upload error. Parameters: `error`: The error. |
| `OnInitialized()` | `void` |  |
| `OnPaste(string html)` | `Task<string>` | Invoked via interop when the user pastes content in RadzenHtmlEditor. Invokes Paste. Parameters: `html`: The HTML. |
| `OnSelectionChange()` | `Task` | Invoked by interop when the RadzenHtmlEditor selection changes. |
| `OnUploadComplete(string response)` | `Task` | Invoked by interop when the upload is complete. |
| `RegisterShortcut(string key, Func<Task> action)` | `void` | Registers a shortcut for the specified action. Parameters: `key`: The shortcut. Can be combination of keys such as CTRL+B. `action`: The action to execute. |
| `RestoreSelectionAsync()` | `Task` | Restores the last saved selection. |
| `SaveSelectionAsync()` | `Task` | Saves the current selection. RadzenHtmlEditor will lose its selection when it loses focus. Use this method to persist the current selection. |
| `SetParametersAsync(ParameterView parameters)` | `Task` |  |
| `UnregisterShortcut(string key)` | `void` | Unregisters the specified shortcut. |

## Inherited Members

- From [FormComponent<string>](https://blazor.radzen.com/docs/api/Radzen.FormComponent-1.md): Change, CurrentPlaceholder, Disabled, EditContext, FieldIdentifier, Form, FormFieldContext, FormFieldLabelledBy, GetClassList, GetValue, HasValue, IsBound, LabelTargetId, LabelToLink, LinkLabelAsync, Name, NotifyFieldChanged, Placeholder, ShouldLinkLabel, TabIndex, Value, ValueChanged, ValueExpression, _value
- From [RadzenComponent](https://blazor.radzen.com/docs/api/Radzen.RadzenComponent.md): AddContextMenu, Attributes, ContextMenu, Culture, CurrentStyle, Debounce, DefaultCulture, DefaultUICulture, Element, GetCssClass, GetId, GetIdAttribute, IsJSRuntimeAvailable, JSRuntime, Localize, MouseEnter, MouseLeave, OnBecameInvisible, OnMouseEnter, OnMouseLeave, RaiseContextMenu, RaiseMouseEnter, RaiseMouseLeave, Reference, Style, UICulture, UniqueID, Visible
- From ComponentBase: Assets, AssignedRenderMode, DispatchExceptionAsync, InvokeAsync, OnAfterRender, OnInitializedAsync, OnParametersSet, OnParametersSetAsync, RendererInfo, ShouldRender, StateHasChanged

