--- title: "@Mentions in the Vue 3 Editor" description: "Set up @mention suggestions in Vue 3 with static or async items in :init, listen for mention-select and mention-remove, and restyle rows with named slots." head: - - meta - name: robots content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - - meta - name: googlebot content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - - meta - name: bingbot content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' --- # @Mentions in the Vue 3 Editor In Vue 3, mentions are configured on the `mentions` key of the object bound to `:init`. Typing `@` opens a suggestion list fed by an array or an async function, picks are reported through the `mention-search`, `mention-select`, and `mention-remove` events, and named slots such as `#mention-item` let you change how each row and state looks. As users type, a debounced autocomplete dropdown appears at the cursor location. Selecting a user inserts a non-editable chip element complete with an accessible hover user card. Mentions are disabled by default. Enable them with `mentions: true` or with an object whose `enabled` value is `true`. The trigger is always `@` and is not configurable. If you need placeholders that the server replaces later, use [merge tags](./merge-tags.html) instead. --- ## Key Highlights

Fixed @ Trigger

In the Vue editor, @ is the fixed trigger. Typing it opens a suggestion list next to the cursor.

Debounced Async Fetching

Set items to an async function. Searches are debounced (200ms by default) and every call receives an AbortSignal for dropping stale requests.

Session Caching

The same query is not fetched twice in one editor session; earlier results are served from a local cache.

Keyboard Navigation

Move with the Up / Down arrows, insert with Enter or Tab, and dismiss the list with Esc.

--- ## Static Mentions To use a fixed list of users, pass an array of `MentionItem` objects in `init.mentions.items`: ```vue ``` Static mentions search case-insensitively across `label`, `description`, and `value`. Matches starting with the search query appear first. --- ## Async Mentions (Fetch API) For dynamic user searches from a database or API endpoint, pass an asynchronous function to `items`: ```vue ``` ### Key Features 1. **Debounce Delay (`debounce: 200`)**: Prevents spamming your backend by waiting 200ms after keypress. 2. **Auto Cancellation (`AbortSignal`)**: Automatically cancels outdated HTTP requests when the user continues typing. 3. **Session Cache**: Caches duplicate queries locally so repeated searches hit memory instead of the network. --- ## Mention Configuration Options | Option | Type | Default | Description | | :------------------ | :-------------------------- | :------ | :------------------------------------------------------------------------------- | | `enabled` | `boolean` | `true` | Enables mention autocomplete when typing `@`. | | `minimumCharacters` | `number` | `0` | Characters required after `@` before searching starts. | | `debounce` | `number` | `200` | Search debounce delay in milliseconds. | | `limit` | `number` | `8` | Maximum visible options in dropdown list. | | `items` | `MentionItem[] \| Function` | `[]` | Static item array or `async (query, signal) => Promise` function. | The detector only opens for a standalone mention query such as `@`, `@da`, or `Hello @damon`. It does not activate inside links, inline code, `
` blocks, existing mentions, non-editable elements, email addresses, URL paths, disabled editors, or readonly editors. Whitespace closes the query.

## Dropdown states and controls

The caret-positioned dropdown supports loading, empty, error, and results states. Failed async requests show a Retry action. The first result is active automatically, and the dropdown flips above the caret when there is not enough viewport space below it.

| Key         | Behavior                                       |
| ----------- | ---------------------------------------------- |
| `ArrowDown` | Select the next result, wrapping at the end.   |
| `ArrowUp`   | Select the previous result, wrapping at start. |
| `Home`      | Select the first result.                       |
| `End`       | Select the last result.                        |
| `Enter`     | Insert the active result.                      |
| `Tab`       | Insert the active result without moving focus. |
| `Escape`    | Close without inserting.                       |

Hovering a result updates the active option. Clicking uses pointer handling that preserves the editor selection, so the mention is inserted once at the original query range.

The default result UI is intentionally compact: each row has a `50px` minimum height, `6px 10px` padding, an `8px` content gap, and a `38px` avatar. The description uses only a `1px` top margin. Override `.erag-mention-dropdown__item`, `.erag-mention-dropdown__avatar`, and `.erag-mention-dropdown__description` after the package stylesheet when a denser or roomier application style is required.

## Hover card

Hover an inserted mention to display its known avatar, label, description, and value. If the avatar is missing or cannot load, the card shows initials. The card remains inside the viewport and uses the item data cached during the current editor session.

---

## Mention Lifecycle Events

Track mention search, insertion, and deletion events in your application:

```vue



```

- **`mention-search`**: Fired with `{ query }` when debounced search starts.
- **`mention-select`**: Fired with `{ item, query }` when a user selects a mention option.
- **`mention-remove`**: Fired with `{ item }` when `Backspace` or `Delete` removes an inserted mention chip.

---

## Mention slots

The editor supplies a complete default UI, but these slots can customize dropdown content without replacing its keyboard handling:

```vue

    

    
    
    

```

---

## HTML Output Format

Inserted mentions render as non-editable inline chips:

```html
@Damon Cross
```

When `value` is absent, `data-erag-mention-value` is omitted. Your server sanitizer should allow these attributes; the list is on the [security and sanitization](./security.html) page. Pressing Backspace immediately after a mention or Delete immediately before it removes the complete chip and keeps the removal undoable.