Mention

A contenteditable rich-text editor for @mention mentions. As the user types @, a dropdown of users appears at the caret; selecting one inserts a non-editable mention token. Includes full keyboard navigation.

Usage

<script>
  import { Mention } from '@vultra/ui';

  let value = $state('');
  const users = [
    { id: '1', name: 'Ada Lovelace' },
    { id: '2', name: 'Grace Hopper', avatar: '/ada.png' }
  ];

  function onMention(user) {
    console.log('Mentioned', user);
  }
</script>

<Mention bind:value {users} placeholder="Write a comment…" {onMention} />

Props

PropTypeDefaultDescription
valuestring''Editor HTML content (bindable)
usersMentionUser[][]Selectable users, filtered by name (bindable)
placeholderstring'Type @ to mention someone…'Placeholder shown when empty
onMention(user: MentionUser) => voidCalled when a mention is inserted
classstringAdditional classes
type MentionUser = { id: string; name: string; avatar?: string };

Keyboard navigation

KeyAction
ArrowUp / ArrowDownMove through the suggestion list
EnterInsert the highlighted mention
EscapeClose the dropdown

The dropdown repositions to the caret as it moves (clicks, selectionchange, undo, etc.).

Features

  • Caret-aware @ trigger with inline dropdown positioned at the caret
  • Non-editable mention tokens that stay intact while typing around them
  • Keyboard navigation (arrows, Enter, Escape)
  • Controlled value + onMention callback

Install

npx @vultra/cli add mention