Extras
RichTextEditor
A native WYSIWYG editor whose HTML you two-way bind with the Value parameter. The toolbar is a flags enum you compose group by group - history, block formats, fonts and colors, inline styles, lists and checklists, links, images, tables, media, alignment and direction, emoji, find & replace, source view and full screen - and it can be reordered or extended with your own buttons. Every byte in and out passes an allowlist sanitizer, and markdown typing rules, a slash menu, mentions, keyboard chords, counting with a limit, localization and EditForm validation are built in.
Notes
To use this component, you need to install the
Bit.BlazorUI.Extras(opens in a new tab)
nuget package, as described in the Optional steps of the
Getting started page.
The content produced by the editor is untrusted input. The component sanitizes every
path in and out of the editor against an allowlist, but that pass runs in the browser
and a browser is not a trust boundary: always sanitize the emitted HTML on the server
before storing or redisplaying it.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Placeholder, size & focus
Readonly & disabled
Two-way binding
<br> the browser leaves behind, so a required
check or a dirty comparison reads it the way it looks.
<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
< that is plainly text ("5 < 10") is left alone - and run through
the active sanitization policy before returning to the WYSIWYG surface.
Sanitization
Plain-text paste
Find & replace
Full screen
Typing shortcuts & slash menu
# through
###### for headings, > for a quote, -,
* or + for a bulleted list, 1. for a numbered
one, [] or [x] for a task, ``` for a code
block, and --- for a divider. Inline markdown closes on its own
delimiter: **bold** or __bold__, *italic* or
_italic_, ~~strikethrough~~ and `code`. None
of these rules - nor autolinking, nor the slash and mention triggers - fire inside a
code block or a code span, where those characters are the content being written.
Enter on the empty last line
of a quote or a code block leaves it for a fresh paragraph, so a block entered by
typing can be left by typing. A typed or pasted URL becomes a link as soon as the word
is finished (turn that off with AutoLink). Typing / on an empty line
opens a command menu you can filter by name or keyword and drive entirely from the
keyboard.
Keyboard shortcuts
- Inline:
bold,italic,underline,strikeThrough,inlineCode - History:
undo,redo - Lists:
insertOrderedList,insertUnorderedList,insertTaskList - Alignment:
justifyLeft,justifyCenter,justifyRight,justifyFull - Indentation:
indent,outdent - Script:
subscript,superscript - Other:
removeFormat,link,unlink,insertHorizontalRule - Paragraph formats:
p,h1-h6,blockquote,pre- these toggle, so the chord that applies a format also takes it back off
Emoji & symbols
Character & word count
EditForm validation
Custom toolbar item
Reordering toolbar groups
Localization
Imperative API
Selection toolbar
Mentions
data-mention-id -
part of the default allowlist, so it survives a save-and-reload round trip - and
OnMentionSelected tells you which record was chosen.
Smart typography
-- becomes an em dash,
... an ellipsis, (c), (r) and (tm)
their symbols, 1/2, 1/4 and 3/4 real fractions,
and ->, <-, !=, <=,
>= and +/- their arrows and math signs. Everything but the
quotes is applied when the space finishes the word, so it is always one undo away, and
nothing is rewritten inside code spans or code blocks. It is off by default: a
document full of code or measurements wants exactly what was typed.
Selection events
Style & Class
RTL
API
Every parameter, public member, sub-class and enum this component exposes.
BitRichTextEditor parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoFocus | bool | false | Automatically moves keyboard focus into the editor after the first render. |
| AutoLink | bool | true | Turns a URL typed into the editor into a link as soon as the word is finished. |
| 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. Negative values are treated as 0. |
| 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. |
| MaxHeight | string? | null | Maximum height of the editing surface (any CSS length). Content beyond it scrolls inside the editor. |
| 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. | |
| OnMentionSearch | Func<string, Task<IReadOnlyList<BitRichTextEditorMention>>>? | null | Supplies the suggestions shown after the user types "@". Leaving it null disables mentions. |
| OnMentionSelected | EventCallback<BitRichTextEditorMention> | Callback for when a mention is picked from the menu. | |
| 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. |
| OnSelectionChange | EventCallback<BitRichTextEditorSelectionState> | Callback for when the selection - or the formatting under it - changes; receives the same snapshot the toolbar highlights itself from. | |
| 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. |
| Resizable | bool | false | Lets the reader drag the bottom edge of the editing surface to make it taller or shorter. |
| 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. |
| ShowQuickToolbar | bool | false | Whether a small formatting toolbar floats next to the current text selection. |
| ShowToolbar | bool | true | Whether the formatting toolbar is shown. |
| SmartTypography | bool | false | Replaces common text patterns with their typographic characters as they are typed: curly quotes, em dash, ellipsis, copyright/registered/trademark signs, fractions, arrows and comparison symbols. |
| SpellCheck | bool | true | Whether the browser's native spell checking runs over the editor content. |
| 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 |
|---|---|---|---|
| CharacterCount | int | The plain-text character count of the current content, as the count footer and MaxLength count it. | |
| ClearAsync | Task | Clears the editor content. | |
| ExecuteCommandAsync | Task | Runs a raw editing command against the editor. | |
| FocusAsync | ValueTask | Moves keyboard focus into the editor. | |
| GetHtmlAsync | ValueTask<string> | Returns the current HTML content of the editor. | |
| GetSelectedTextAsync | ValueTask<string> | Returns the plain text of the current selection, or an empty string when nothing inside the editor is selected. | |
| GetTextAsync | ValueTask<string> | Returns the current content of the editor as plain text, with block boundaries rendered as newlines and all markup removed. | |
| InsertHtmlAsync | Task | Inserts HTML at the current caret position, after running it through the active sanitization policy. | |
| InsertTextAsync | Task | Inserts plain text at the current caret position, honoring MaxLength. | |
| IsEmpty | bool | Whether the editor holds nothing a reader would see - no text and none of the elements that are content without carrying text (images, tables, rules, media). | |
| RedoAsync | Task | Redoes the last undone edit. | |
| SelectAllAsync | ValueTask | Selects the whole editor content. | |
| SetHtmlAsync | Task | Replaces the whole content with the given HTML (sanitized), or clears it when null/empty. | |
| UndoAsync | Task | Undoes the last edit. | |
| WordCount | int | The word count of the current content. |
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. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| 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). Use BitRichTextEditorToolbarConfig.GroupIds for the built-in 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. It must not collide with a built-in group id. | |
| 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. |
BitRichTextEditorSanitizationPolicy properties
An allowlist sanitization policy. Only the listed tags, attributes, and URI schemes are retained; everything else is removed. The static Default property returns a fresh copy of the built-in policy.
| Name | Type | Default value | Description |
|---|---|---|---|
| AllowedTags | ISet<string> | Permitted (lowercase) element/tag names. | |
| AllowedAttributes | IDictionary<string, ISet<string>> | Permitted attributes per tag name. Use the key "*" for attributes allowed on any tag. A permitted style attribute is filtered further, down to presentational CSS properties. | |
| AllowedUriSchemes | ISet<string> | Permitted URI schemes for href/src attributes (e.g. http, https, mailto). | |
| AllowDataImageUris | bool | true | Whether data: image URIs are permitted in image sources. |
| AllowedIframeHosts | IReadOnlyCollection<string>? | null | Hosts an iframe may point at, over https. Null applies the built-in approved embed hosts (YouTube, YouTube-nocookie, Vimeo); an empty collection permits no iframe at all; a single "*" entry lifts the restriction and lets any https source through. |
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. |
BitRichTextEditorSelectionState properties
Snapshot of the formatting under the selection, reported to OnSelectionChange and used to highlight the toolbar.
| Name | Type | Default value | Description |
|---|---|---|---|
| Bold | bool | false | Whether the selection is bold. |
| Italic | bool | false | Whether the selection is italic. |
| Underline | bool | false | Whether the selection is underlined. |
| StrikeThrough | bool | false | Whether the selection is struck through. |
| InlineCode | bool | false | Whether the selection sits inside an inline code span (not a code block). |
| Subscript | bool | false | Whether the selection is subscript. |
| Superscript | bool | false | Whether the selection is superscript. |
| OrderedList | bool | false | Whether the selection sits in a numbered list. |
| UnorderedList | bool | false | Whether the selection sits in a bulleted list. |
| TaskList | bool | false | Whether the selection sits in a checklist item. |
| JustifyLeft | bool | false | Whether the block is aligned left. |
| JustifyCenter | bool | false | Whether the block is centered. |
| JustifyRight | bool | false | Whether the block is aligned right. |
| JustifyFull | bool | false | Whether the block is justified. |
| Block | string | "" | The current block tag ("p", "h1", "blockquote", "pre", ...), lowercase. |
| Direction | string? | null | Text direction of the selected block ("ltr"/"rtl"), or null. |
| ForeColor | string? | null | Active text color of the selection, or null when mixed/none. |
| BackColor | string? | null | Active highlight color of the selection, or null when mixed/none. |
| FontName | string? | null | Active font family, or null when the selection spans several. |
| FontSize | string? | null | Active font size as a CSS length, or null when the selection spans several. |
| InLink | bool | false | Whether the selection sits inside a hyperlink. |
| LinkHref | string? | null | The href of the link under the selection, or null when none/multiple. |
| LinkNewTab | bool | false | Whether that link opens in a new tab (target="_blank"). |
| InTable | bool | false | Whether the selection sits inside a table cell, which is what enables the table operations. |
| ImageSelected | bool | false | Whether an image inside the editor is selected. |
| ImageAlign | string? | null | Alignment of the selected image ("left", "center", "right"), or null when it flows inline. |
| ImageSrc | string? | null | Source of the selected image, or null when no image is selected. |
| ImageAlt | string? | null | Alternative text of the selected image (empty when it has none), or null when no image is selected. |
| HasSelection | bool | false | Whether a non-empty range inside the editor is selected. |
| SelectionTop | double | 0 | Top of the selection rectangle, in pixels relative to the component root. |
| SelectionLeft | double | 0 | Left edge of the selection rectangle, in pixels relative to the component root. |
| SelectionWidth | double | 0 | Width of the selection rectangle in pixels. |
| SelectionHeight | double | 0 | Height of the selection rectangle in pixels. |
BitRichTextEditorMention properties
A single suggestion offered by the mention menu.
| Name | Type | Default value | Description |
|---|---|---|---|
| Id | string | Stable identifier written into the inserted markup as data-mention-id. | |
| Display | string | The text shown in the menu and inserted after the trigger character. | |
| Description | string? | null | Optional secondary line shown under the display text in the menu. |
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. |
IBitRichTextEditorLocalizer properties
Provides localized labels and tooltips for the editor's controls.
| Name | Type | Default value | Description |
|---|---|---|---|
| this[string key] | string? | Returns the localized string for the given key, or null to use the built-in English default. |
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
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.