Mention Input

A text box where typing @ shows a list of people and agents to tag, like in Slack or Linear.

Preview

Setup

Install with the shadcn CLI

$npx shadcn@latest add https://kinetikui.singhgourav.site/r/mention-input.json

One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.

Or install manually

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge framer-motion lucide-react
  2. 2

    Copy lib/utils.ts from the Code tab. Skip if you already have cn().

  3. 3

    Copy styles/tokens.css from the Code tab and import it in your global CSS after Tailwind: @import "./styles/tokens.css";

  4. 4

    This component uses Popover Menu. Copy components/ui/popover-menu/ from the Code tab too, at the same path so the import resolves. Skip any you already have.

  5. 5

    Create a components/ui/mention-input/ folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest.

  6. 6

    Import and render:

    Example
    import { MentionInput } from "@/components/ui/mention-input"
    
    <MentionInput
      mentions={[{ id: "jane", name: "Jane Moore", kind: "person" }]}
      onSubmit={(text) => console.log(text)}
    />

Usage

Give it a list of people and agents, and what to do when someone presses Enter:

Example
import { MentionInput } from "@/components/ui/mention-input"

const people = [
  { id: "rune", name: "Rune", description: "CRM assistant", kind: "agent" },
  { id: "jane", name: "Jane Moore", description: "Admin", kind: "person" },
]

<MentionInput mentions={people} onSubmit={(text) => send(text)} />

How it works for the person typing:

  • Type @, or press the @ button, and the list opens.
  • Keep typing to narrow it down. ↑ ↓ move, Enter or Tab picks, Esc closes.
  • Picking adds @Name to the text, and they carry on typing.

Agents show in a square tile, people as a round initial. Set color on an item to change its color, and icon to put your own icon in an agent's tile instead of the sparkle.

Profile cards on sent messages

MentionText shows a message with each @Name highlighted. Hovering a name (or tabbing to it) opens a small profile card, like in Slack, with their photo or initials, role, status and local time, and icon buttons to message them or open their profile.

Example
import { MentionText } from "@/components/ui/mention-input"

const people = [
  {
    id: "jane",
    name: "Jane Moore",
    kind: "person",
    title: "Head of Operations",
    status: "online", // "online" | "away" | "offline"
    timeZone: "America/New_York",
    avatar: "/jane.jpg", // optional, initials otherwise
  },
]

<MentionText
  text="Can you look at this, @Jane Moore?"
  mentions={people}
  onMessage={(person) => openChat(person.id)}
  onViewProfile={(person) => router.push(`/people/${person.id}`)}
/>

The card opens after a short pause and stays open while the pointer moves into it. It flips above or below the name, and left or right, so it stays inside the box around it. Leave out onMessage or onViewProfile to hide that icon button. MentionCard is the card on its own.

The card's edge is BorderShine: a hairline border that's lighter at the top left and tinted with your accent at the bottom right, with one sweep of light when the card appears. Drop it into any relative rounded box to give it the same edge.

Using your own text box

Already have a textarea? useMentions adds the same @ list to it:

Example
import { useMentions } from "@/components/ui/mention-input"

const ref = useRef<HTMLTextAreaElement>(null)
const mention = useMentions({ mentions: people, value, onChange: setValue, textareaRef: ref })

<div className="relative">
  {mention.menu}
  <textarea
    ref={ref}
    value={value}
    onChange={(e) => {
      setValue(e.target.value)
      mention.onChange(e)
    }}
    onSelect={mention.onSelect}
    onKeyDown={(e) => {
      if (mention.onKeyDown(e)) return // the list used the key
      // your own keys here
    }}
  />
</div>

Props

PropTypeDefaultWhat it does
mentionsMention[]—The list. Each item: id, name, kind ("agent" or "person"), and optional description, color and icon. For profile cards also avatar, title, status and timeZone.
onSubmit(text) => void—Called on Enter. Adds a send button. Leave it out for a plain text box.
value / defaultValue / onValueChangestring""The text, if you want to control it.
placeholderstring“Type @ to mention someone…”

Accessibility

  • Focus stays in the text box while the list is open, so typing never gets interrupted
  • The text box is marked as having a list (aria-autocomplete, aria-expanded)
  • The @ and send buttons are labeled
  • Mentions in MentionText are buttons: focusing one opens its profile card, Escape closes it and keeps focus on the name
  • The card is a labeled dialog (aria-haspopup, aria-expanded, aria-controls on the name), and its animation drops to a plain fade with reduced motion