EditorSuggestionMenu
A slash menu that inserts blocks and formats. Items come from .NET; filtering and keys run in the browser.
Examples
Custom commands
Up and down move, Enter or Tab insert, Escape closes. The text field announces the list as a combobox while it is open.
Type / and keep typing to filter, then press Enter.
Razor
<div class="flex w-full max-w-2xl flex-col gap-3">
<KlyFormField Label="Slash menu" Help="Type / and keep typing to filter, then press Enter.">
<KlyEditor Value="@("")" Name="slash" Placeholder="Type / for commands" data-testid="editor-slash">
<KlyEditorSuggestionMenu Items="Items" />
</KlyEditor>
</KlyFormField>
</div>
@code {
private static readonly EditorSuggestionItem[] Items =
[
new(EditorAction.Heading, "Big title") { Level = 1, Description = "Heading 1", Keywords = "h1 heading" },
new(EditorAction.Heading, "Section") { Level = 2, Description = "Heading 2", Keywords = "h2 heading" },
new(EditorAction.BulletList, "Bullets") { Description = "A list of points" },
new(EditorAction.Blockquote, "Quote") { Description = "Quote a passage" },
new(EditorAction.HorizontalRule, "Divider") { Description = "A horizontal line" },
];
}API
KlyEditorSuggestionMenu
The slash menu: opens when "/" is typed (after a space or at the start of a block) and inserts a block or a format. Items run in the browser: pass them as a parameter, no round trip is made while the user types.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Char |
string |
Character that opens the menu. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Items |
IReadOnlyList |
Entries of the menu. Defaults to KlyMessages) of the messages of the locale in effect. | |
Label |
string |
Accessible name of the list. | |
Limit |
int |
42 |
Most options shown at a time. |
Size |
KlySize |
KlySize. |
Size of the menu, from Xs to Xl . Values: Xs, Sm, Md, Lg, Xl. |
Ui |
EditorMenuUi |
Per-instance class overrides of the slots of the menu, see EditorMenuUi . |
Ui slots
Ui takes a EditorMenuUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
Content |
Classes merged into the content slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
Listbox |
Classes merged into the listbox slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
Icon |
Classes merged into the icon slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
Body |
Classes merged into the body slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
ItemLabel |
Classes merged into the itemLabel slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
ItemDescription |
Classes merged into the itemDescription slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
Empty |
Classes merged into the empty slot of KlyEditorSuggestionMenu , KlyEditorMentionMenu and KlyEditorEmojiMenu , after the theme and the app configuration. |
EditorSuggestionItem
An entry of KlyEditorSuggestionMenu : a block or a format the user can insert.
Parameters
| Name | Type | Description |
|---|---|---|
Action |
EditorAction |
What the entry inserts or applies. Values: Bold, Italic, Strike, Underline, Code, Paragraph, Heading, BulletList, OrderedList, TaskList, Blockquote, CodeBlock, HorizontalRule, Link, Image, ClearFormatting, Undo, Redo, MoveUp, MoveDown. |
Description |
string |
Text shown under the label. |
Disabled |
bool |
Disables the entry. |
Keywords |
string |
Extra words the typed text is matched against. |
Label |
string |
Text of the entry. |
Level |
int |
Heading level for Heading . |