Slash Menu in the ASP.NET MVC Rich Text Editor control
18 Nov 20182 minutes to read
The Slash Menu in the Rich Text Editor provides users with an efficient way to apply formatting, insert elements, and execute custom commands by simply typing the “/” character. This feature enhances the user experience by offering quick access to common editing actions within the editor.
Enabling the Slash Menu
To use the Slash Menu feature, inject SlashMenuService in the provider section of AppComponent.
To enable the Slash Menu, set the Enable property within SlashMenuSettings to true. By default, this feature is disabled. Once enabled, the Slash Menu will appear when the user types the “/” character in the editor.
Configuring the Slash Menu Items
The slashMenuSettings property allows customization of the Items displayed in the Slash Menu. By defining the Items property, a list of available commands can be provided for users to choose from when they type a slash (/) in the Rich Text Editor.
This list can include various formatting options such as paragraph and heading levels. Here’s an code snippet of configuring the Slash Menu items:
ViewBag.SlashMenuSettings = new Syncfusion.EJ2.RichTextEditor.RichTextEditorSlashMenuSettings
{
Enable = true,
Items = new object[] { "Paragraph", "Heading 1", "Heading 2", "Heading 3" },
};
Customizing the Popup Width and Height
The size of the Slash Menu popup can be customized using the PopupWidth and PopupHeight properties within slashMenuSettings. Adjusting these values allows for control over the dimensions of the menu.
Below is an code snippet showing how to customize both the width and height of the popup:
ViewBag.SlashMenuSettings = new Syncfusion.EJ2.RichTextEditor.RichTextEditorSlashMenuSettings
{
Enable = true,
Items = new object[] { "Paragraph", "Heading 1", "Heading 2", "Heading 3" },
PopupHeight = "300px",
PopupWidth = "250px"
};
Adding Custom Slash Menu Items
Custom items can be added by defining the items property inside slashMenuSettings. This property accepts either a string of predefined items or an array of objects representing custom menu items.
Each custom item object can include the following properties:
| Property | Description |
|---|---|
| text | The label of the menu item. |
| command | The action to be executed when the item is clicked. |
| type | Groups related items in the Slash Menu. |
| iconCss | Specifies the CSS class for the item’s icon. |
| description | Provides a short description for the item. |
The following code demonstrates how to set up the Custom Slash Menu item in the Rich Text Editor to insert meeting notes and signature: