Emoji Picker in the ASP.NET MVC Rich Text Editor Control

21 Mar 202513 minutes to read

An emoji picker is a tool designed for adding emojis or emoticons to text with ease. It usually appears as a small window or panel showcasing a variety of emojis categorized into sections such as smileys, animals, food, and more. The desired emoji can be selected by clicking on it or typing its name into a search bar.

Configuring Emoji Picker Tool with Custom Emojis in the Toolbar

Add the EmojiPicker tool to the Rich Text Editor toolbar using the ToolbarSettings Items property.

By default, a predefined set of emojis is configured. However, these icons can be customized according to specific needs by using the EmojiPickerSettings property.

The following code example shows how to customize icons in the emoji picker.

@Html.EJS().RichTextEditor("emojiPickerRTE").ToolbarSettings(e => e.Items((object)ViewBag.items)).EmojiPickerSettings(e => e.IconsSet((object)ViewBag.iconsSet)).Value(ViewBag.value).Render()
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.value = @"<p>An emoji picker in a Rich Text Editor is a tool that allows users to easily add emojis or emoticons to their text.</p>
        <p>Typically, it is a small window or panel that displays a variety of emojis, arranged in different categories, such as smileys, animals, food, and so on. Users can select the desired emoji by clicking on it or by typing its name in a search bar.</p>";
        ViewBag.items = new[]
        {
            "EmojiPicker", "ClearFormat", "Bold", "Italic", "Underline", "|",
            "Formats", "Alignments", "OrderedList", "UnorderedList", "|",
            "CreateLink", "Image", "|", "SourceCode", "Undo", "Redo"
        };

        ViewBag.iconsSet = new[]
        {
            new
            {
                name = "Smilies & People",
                code = "1F600",
                iconCss = "e-emoji",
                icons = new[]
                {
                    new { code = "1F600", desc = "Grinning face" },
                    new { code = "1F603", desc = "Grinning face with big eyes" },
                    new { code = "1F604", desc = "Grinning face with smiling eyes" },
                    new { code = "1F606", desc = "Grinning squinting face" },
                    new { code = "1F605", desc = "Grinning face with sweat" },
                    new { code = "1F602", desc = "Face with tears of joy" },
                    new { code = "1F923", desc = "Rolling on the floor laughing" },
                    new { code = "1F60A", desc = "Smiling face with smiling eyes" }
                }
            },
            new {
                name = "Animals & Nature",
                code = "1F435",
                iconCss = "e-animals",
                icons = new[] {
                    new { code = "1F436", desc = "Dog face" },
                    new { code = "1F431", desc = "Cat face" },
                    new { code = "1F42D", desc = "Mouse face" },
                    new { code = "1F439", desc = "Hamster face" },
                    new { code = "1F430", desc = "Rabbit face" },
                    new { code = "1F98A", desc = "Fox face" }
                }
            },
            new {
                name = "Food & Drink",
                code = "1F347",
                iconCss = "e-food-and-drinks",
                icons = new[] {
                    new { code = "1F34E", desc = "Red apple" },
                    new { code = "1F34C", desc = "Banana" },
                    new { code = "1F347", desc = "Grapes" },
                    new { code = "1F353", desc = "Strawberry" },
                    new { code = "1F35E", desc = "Bread" },
                    new { code = "1F950", desc = "Croissant" },
                    new { code = "1F955", desc = "Carrot" },
                    new { code = "1F354", desc = "Hamburger" }
                }
            },
            new {
                name = "Activities",
                code = "1F383",
                iconCss = "e-activities",
                icons = new[] {
                    new { code = "26BD", desc = "Soccer ball" },
                    new { code = "1F3C0", desc = "Basketball" },
                    new { code = "1F3C8", desc = "American football" },
                    new { code = "26BE", desc = "Baseball" },
                    new { code = "1F3BE", desc = "Tennis" },
                    new { code = "1F3D0", desc = "Volleyball" },
                    new { code = "1F3C9", desc = "Rugby football" }
                }
            },
        };
        return View();
    }
}

Additionally, you have the option to customize the icons of toolbar items using the IconCss and Code properties. The IconCSS property allows you to define a custom CSS class for the toolbar item icon, while the Code property enables you to specify the Unicode character code for the icon.

When both IconCSS and Code properties are provided, the IconCSS property takes precedence in determining the appearance of the toolbar item icon.

Additionally, you have the option to enhance the user experience by implementing a filtering feature for efficiently managing a large dataset of emojis. By setting the ShowSearchBox property to true (which is the default value), users will be able to utilize a search box to filter the displayed emojis according to their preferences.

The following code example shows how to add the emoji picker tool in the Rich Text Editor.

@Html.EJS().RichTextEditor("emojiPickerRTE").ToolbarSettings(e => e.Items((object)ViewBag.items)).Value(ViewBag.value).Render()
public class HomeController : Controller
{

    public ActionResult Index()
    {
        ViewBag.value = @"<p>An emoji picker in a Rich Text Editor is a tool that allows users to easily add emojis or emoticons to their text.</p>
        <p>Typically, it is a small window or panel that displays a variety of emojis, arranged in different categories, such as smileys, animals, food, and so on. Users can select the desired emoji by clicking on it or by typing its name in a search bar.</p>";
        
        ViewBag.items = new[] { "EmojiPicker"};

        return View();
    }
}

Using Shortcut Keys to Open the Emoji Picker

Quickly access the emoji picker by pressing the colon (:) key while typing a word prefix in an editor, allowing instant emoji selection and display. Moreover, continue typing in the editor after the colon (:) to filter and refine your search for the desired emojis.

Rich Text Editor Emoji Picker

The emoji picker popup offers keyboard navigation options, allowing you to move the emoji focus from one emoji to another. The following keys are used for navigation:

Arrow keys: Use the arrow keys (up, down, left, right) to move the emoji focus in the corresponding direction.

Enter: Press Enter key to select the currently focused emoji.

Escape: Press Escape to close the emoji picker popup without selecting an emoji.