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
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
Array of trigger configurations. Each trigger defines a character(s) that opens the mention dropdown.
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
MentionItem objectsDebounce delay for search in milliseconds. Reduces API calls while user is typing.
Minimum query length before triggering search. Set to
1 or higher to avoid searching on empty
query.Called when a mention is selected.Signature:
Called when dropdown opens.Signature:
Called when dropdown closes.Signature:
Close dropdown when item is selected.
Close dropdown on click outside.
Close dropdown on Escape key.
Element Props
Unique identifier for the mention
Display name of the mention (e.g., “John Doe”)
URL to avatar image
Type of mention (e.g.,
'user', 'channel', 'page', 'custom')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:
- Apply the theme to your plugins
- 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 theuseMentionDropdown 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
Debounce Search Requests
Debounce Search Requests
Use the
debounceMs option to reduce API calls while users are typing. A value of 300ms is usually optimal.Set Minimum Query Length
Set Minimum Query Length
Use
minQueryLength: 1 or higher to avoid searching on empty queries, which can be expensive.Handle Loading States
Handle Loading States
Show loading indicators in your custom dropdown while search is in progress.
Provide Fallbacks
Provide Fallbacks
Handle search errors gracefully and provide user feedback.
Limit Results
Limit Results
Return a reasonable number of results (e.g., 10-20) to avoid overwhelming users.
Use Types for Organization
Use Types for Organization
Use the
type field to categorize mentions and enable different search logic per type.Hooks
useMentionDropdown
Hook for building custom mention dropdowns:Troubleshooting
Dropdown not opening
Dropdown not opening
Make sure you’ve:
- Wrapped your editor with
withMentions() - Configured the
onSearchoption - Added the
MentionDropdowncomponent to your editor (when using themes)
Search not working
Search not working
Check that your
onSearch function:- Returns a Promise
- Returns an array of
MentionItemobjects - Each item has
idandnameproperties
Mention not inserting
Mention not inserting
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.
Multiple triggers not working
Multiple triggers not working
When using multiple triggers, make sure you’re using the
triggers array instead of the char option.Solution:Related Plugins
- Link Plugin - For hyperlinks
- Paragraph Plugin - For text blocks that support mentions