RichTextEditor
RichTextEditor is a native WYSIWYG text editor. Component state and the public API live in C#; browser editing operations (contenteditable events, formatting commands, and selection management) are handled in the JS/TypeScript bridge.
Notes
To use this component, you need to install the
Bit.BlazorUI.Extras
nuget package, as described in the Optional steps of the
Getting started page.
The content produced by the editor is untrusted input. Although the component strips obvious
script vectors, you should still sanitize the emitted HTML on the server before storing or
redisplaying it.
Usage
Basic
Placeholder & height
Readonly
Two-way binding
<p>The bound value is just a <strong>string</strong> you own.</p>
Debounce
<p>Type and watch the value update after the debounce window.</p>
Focus & blur events
Formatting
Indentation & scripts
Toolbar groups
Full toolbar
Links
Images
Colors
Fonts
Tables
Media & rules
Source view
Sanitization
Plain-text paste
Find & replace
Full screen
Slash menu
Keyboard shortcuts
- Inline:
bold,italic,underline,strikeThrough - History:
undo,redo - Lists:
insertOrderedList,insertUnorderedList - Alignment:
justifyLeft,justifyCenter,justifyRight,justifyFull - Indentation:
indent,outdent - Script:
subscript,superscript - Other:
removeFormat,unlink,insertHorizontalRule
Emoji
Character & word count
EditForm validation
Custom toolbar item
Reordering toolbar groups
Imperative API
Style & Class
API
BitRichTextEditor parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Classes | BitRichTextEditorClassStyles? | null | Custom CSS classes for different parts of the rich text editor. |
| DebounceMs | int | 200 | Debounce window (ms) for content-change notifications while typing. |
| FontFamilies | IReadOnlyList<string>? | null | Font families offered in the font-family selector. Null/empty uses defaults. |
| FontSizes | IReadOnlyList<string>? | null | Font sizes offered in the font-size selector. Null/empty uses defaults. |
| Height | string | 300px | Minimum height of the editing surface (any CSS length). |
| KeyboardShortcuts | IReadOnlyDictionary<string, string>? | null | Custom key-combo to command map, merged over the built-in defaults. |
| Localizer | IBitRichTextEditorLocalizer? | null | Localized labels/tooltips provider. Null uses built-in English labels. |
| MaxLength | int? | null | Maximum plain-text character count. Null means unlimited. |
| OnBlur | EventCallback | Callback for when the editor loses focus. | |
| OnChange | EventCallback<string?> | Callback for when the editor content changes. | |
| OnError | EventCallback<BitRichTextEditorError> | Callback for when the editor encounters a recoverable error. | |
| OnFocus | EventCallback | Callback for when the editor gains focus. | |
| OnImageUpload | Func<BitRichTextEditorImageUpload, Task<string?>>? | null | Invoked to persist an image binary, returning the URL to embed. When null, dropped or pasted images are embedded as inline data URLs. |
| PasteAsPlainText | bool | false | When true, pasted content is inserted as plain text. |
| Placeholder | string? | null | The placeholder value of the editor shown while it is empty. |
| ReadOnly | bool | false | Makes the editor readonly. |
| SanitizationPolicy | BitRichTextEditorSanitizationPolicy? | null | Allowlist policy applied to all content. When null a secure default allowlist is applied. |
| ShowCount | bool | false | Show the character/word count footer. |
| ShowToolbar | bool | true | Whether the formatting toolbar is shown. |
| Styles | BitRichTextEditorClassStyles? | null | Custom CSS styles for different parts of the rich text editor. |
| Toolbar | BitRichTextEditorToolbar | BitRichTextEditorToolbar.All | Which toolbar groups to display. |
| ToolbarConfig | BitRichTextEditorToolbarConfig? | null | Custom toolbar items and ordering. Null uses the default group order. |
| Value | string? | null | The two-way bound HTML content of the editor. |
BitRichTextEditor public members
| Name | Type | Default value | Description |
|---|---|---|---|
| FocusAsync | ValueTask | Moves keyboard focus into the editor. | |
| GetHtmlAsync | ValueTask<string> | Returns the current HTML content of the editor. | |
| ExecuteCommandAsync | Task | Runs a raw editing command against the editor. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitRichTextEditorClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root of the BitRichTextEditor. |
| Toolbar | string? | null | Custom CSS classes/styles for the toolbar of the BitRichTextEditor. |
| Group | string? | null | Custom CSS classes/styles for the toolbar groups of the BitRichTextEditor. |
| Button | string? | null | Custom CSS classes/styles for the toolbar buttons of the BitRichTextEditor. |
| Editor | string? | null | Custom CSS classes/styles for the editor (content) area of the BitRichTextEditor. |
| Source | string? | null | Custom CSS classes/styles for the HTML source view textarea of the BitRichTextEditor. |
| Count | string? | null | Custom CSS classes/styles for the character/word count footer of the BitRichTextEditor. |
BitRichTextEditorToolbarConfig properties
Configures toolbar ordering and custom items.
| Name | Type | Default value | Description |
|---|---|---|---|
| Order | IReadOnlyList<string>? | null | Explicit ordering of toolbar entry ids (built-in group ids and custom item ids). |
| CustomItems | IReadOnlyList<BitRichTextEditorToolbarItem>? | null | Custom toolbar items (max 50 are rendered). |
BitRichTextEditorToolbarItem properties
A custom toolbar button supplied by the host.
| Name | Type | Default value | Description |
|---|---|---|---|
| Id | string | Unique id used for ordering and lookup. | |
| Label | string? | null | Text label shown when no icon is provided. |
| Icon | RenderFragment? | null | Optional icon content. |
| AriaLabel | string? | null | Optional accessible label / tooltip. When omitted, Label is used as the accessible name. |
| OnActivate | Func<BitRichTextEditor, Task> | Action invoked when the item is activated; receives the editor instance. |
BitRichTextEditorImageUpload properties
An image to be persisted by the host's OnImageUpload delegate.
| Name | Type | Default value | Description |
|---|---|---|---|
| FileName | string | Original file name, when available. | |
| ContentType | string | MIME type, e.g. "image/png". | |
| Content | byte[] | Raw image bytes. |
BitRichTextEditorError properties
An error surfaced by the editor (e.g. invalid URL, failed upload, invalid HTML).
| Name | Type | Default value | Description |
|---|---|---|---|
| Code | string | Stable error code, e.g. "invalid-url". | |
| Message | string | Human-readable description. |
BitRichTextEditorToolbar enum
| Name | Value | Description |
|---|---|---|
| None | 0 | |
| History | 1 | |
| BlockFormat | 2 | |
| Inline | 4 | |
| Lists | 8 | |
| Blocks | 16 | |
| Link | 32 | |
| Alignment | 64 | |
| Clear | 128 | |
| Image | 256 | |
| Color | 512 | |
| Font | 1024 | |
| Indent | 2048 | |
| Script | 4096 | |
| Source | 8192 | |
| Table | 16384 | |
| Media | 32768 | |
| Rule | 65536 | |
| Emoji | 131072 | |
| Find | 262144 | |
| FullScreen | 524288 | |
| Direction | 1048576 | |
| All | 255 | |
| AllExtended | 2097151 |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
You can give us your feedback through our GitHub repo by filing a new Issue or starting a new Discussion.
Or you can review / edit this page on GitHub.
- On this page