Components

Caret-Anchored Mention Popover

Type @ and the people popover opens at the text caret, not under the field. Textareas won't give you the caret's x·y, so a hidden mirror re-typesets everything before it and reads a marker's offset. The popover glides after the caret as you type, its rows cascade in, its height eases as the list filters, and it clamps to the card and flips above when the screen runs out. ↑↓ + Enter pick a person while focus never leaves the textarea (aria-activedescendant), and inserted names render as pills painted by a transparent overlay behind the real text. Tick Anchor to field to feel the usual shortcut.

@ to mention

Popover: closed · Last mention: none

Install

npx moumenlab add caret-mention-popover

For AI

Open .md

Usage

"use client";

import MentionComposer from "./caret-mention-popover";

export default function MentionComposerExample() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      {/* Type @ to mention. Pass your people and handle onSubmit(text, mentions). */}
      <MentionComposer
        people={[
          { name: "Sarah Chen", handle: "sarahchen" },
          { name: "Omar Farouk", handle: "omarfarouk" },
          { name: "June Park", handle: "junepark" },
        ]}
        onSubmit={(text, mentions) => console.log("send", text, mentions)}
      />

      {/* anchor="field" is the usual dropdown shortcut — under the field, not the caret. */}
      <MentionComposer anchor="field" />
    </div>
  );
}