Skip to main content

Overview

The Mention plugin enables users to mention people, channels, pages, or any custom resources by typing a trigger character (default: @). It provides an autocomplete dropdown with search functionality and customizable rendering.

Installation

Basic Usage

Pass the plugin to createYooptaEditor (wrapped with withMentions); do not pass plugins to <YooptaEditor>. Add MentionDropdown as a child when using theme UI.
Required ConfigurationYou must configure the onSearch option. Without this option, the mention dropdown won’t work.
See the Configuration section below for detailed examples.

Features

  • Multiple Triggers: Support for multiple trigger characters (e.g., @ for users, # for channels)
  • Autocomplete Dropdown: Searchable dropdown with keyboard navigation
  • Custom Search: Implement your own search logic (API calls, local filtering, etc.)
  • Type Support: Categorize mentions by type (user, channel, page, custom)
  • Rich Metadata: Store additional data with each mention (avatar, email, URL, etc.)
  • Hover Cards: Display mention details on hover (when using themes)
  • Keyboard Navigation: Arrow keys, Enter, Escape support
  • Debounced Search: Configurable debounce delay for search requests

Configuration

Basic Configuration

Multiple Triggers

You can configure multiple trigger characters for different types of mentions:

Advanced Configuration

Options

MentionTrigger[]
Array of trigger configurations. Each trigger defines a character(s) that opens the mention dropdown.
string
default:"'@'"
Simple single trigger character (shorthand for triggers: [{char}]). Use this for a single trigger, or use triggers array for multiple triggers.
Search function called when user types after trigger.Signature:
Parameters:
  • query - The search query (without trigger char)
  • trigger - The trigger that opened the dropdown
Returns: Promise resolving to array of MentionItem objects
number
default:"300"
Debounce delay for search in milliseconds. Reduces API calls while user is typing.
number
default:"0"
Minimum query length before triggering search. Set to 1 or higher to avoid searching on empty query.
function
Called when a mention is selected.Signature:
function
Called when dropdown opens.Signature:
function
Called when dropdown closes.Signature:
boolean
default:"true"
Close dropdown when item is selected.
boolean
default:"true"
Close dropdown on click outside.
boolean
default:"true"
Close dropdown on Escape key.

Element Props

string
required
Unique identifier for the mention
string
required
Display name of the mention (e.g., “John Doe”)
string
URL to avatar image
string
Type of mention (e.g., 'user', 'channel', 'page', 'custom')
object
Additional metadata for the mention. Can contain any custom fields:

Commands

Using with Themes

When using a theme (e.g., @yoopta/themes-shadcn), you need to:
  1. Apply the theme to your plugins
  2. Add the MentionDropdown component to your editor

Custom Rendering

You can customize how mentions are rendered:

Custom Dropdown

You can create a custom dropdown using the useMentionDropdown hook:

Parsers

HTML Deserialization

The plugin automatically deserializes mention spans:

HTML Serialization

Markdown Serialization

Email Serialization

Use Cases

User Mentions

Mention team members in comments or posts

Channel Mentions

Reference channels or topics with #

Page Links

Link to pages or documents with [[

Custom Resources

Mention any custom resource type

Best Practices

Use the debounceMs option to reduce API calls while users are typing. A value of 300ms is usually optimal.
Use minQueryLength: 1 or higher to avoid searching on empty queries, which can be expensive.
Show loading indicators in your custom dropdown while search is in progress.
Handle search errors gracefully and provide user feedback.
Return a reasonable number of results (e.g., 10-20) to avoid overwhelming users.
Use the type field to categorize mentions and enable different search logic per type.

Hooks

useMentionDropdown

Hook for building custom mention dropdowns:

Troubleshooting

Check that your onSearch function:
  1. Returns a Promise
  2. Returns an array of MentionItem objects
  3. Each item has id and name properties
Solution:
Make sure the mention is being inserted in a block that supports inline elements (e.g., Paragraph, Heading).Solution: Mentions are inline elements and can only be inserted in blocks that support inline content.
When using multiple triggers, make sure you’re using the triggers array instead of the char option.Solution: