How it works
There is no contenteditable. The textarea draws only the caret and selection; a mirror with the same box model sits behind it and draws the text, with each mention as an accent token. A hidden second mirror measures the caret so the list opens under the @, clamped inside the field. Text stays a plain string, easy to store and diff.
Use it for
- Comments, replies and notes where people notify teammates by name.
- Any message field that must keep native mobile keyboards, autocorrect and IME.
Look elsewhere when
- Rich formatting (bold, links, images): use a rich-text editor.
- Picking recipients only, without free text: use a tags input or multi-select.
Usage
import { useState } from 'react'
import { MentionInput } from './MentionInput.jsx'
const people = [
{ id: 'm', name: 'Mira Holt', role: 'Design lead' },
{ id: 'j', name: 'Jonas Reed', role: 'Illustrator' },
]
export function Reply() {
const [text, setText] = useState('')
return (
<MentionInput
aria-label="Reply"
value={text}
onChange={(next, mentioned) => setText(next)}
people={people}
placeholder="Type @ to mention someone"
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
people | { id?, name, role?, handle?, color? }[] | — | Who can be mentioned. A word of name or the handle is matched from its start. |
value | string | — | Controlled text. Mentions are stored as plain "@Name". |
defaultValue | string | '' | Initial text when uncontrolled. |
onChange | (text, mentioned: Person[]) => void | — | Called on every edit with the text and the people currently mentioned in it. |
trigger | string | '@' | Character that starts a mention; it must follow a space or the start. |
rows | number | 3 | Visible rows of the textarea. |
maxLength | number | — | Character limit; shows a counter that turns amber past 90%. |
renderPerson | (person) => ReactNode | — | Replaces the default initial avatar in the list. |
labels | object | — | Replaces built-in text: people, noMatch, mentioned. |
...rest | TextareaHTMLAttributes | — | Go to the textarea, including onKeyDown (called after list navigation) and aria-label. List layer: --ds-mention-z (30). |
Accessibility
- The textarea is a combobox (aria-autocomplete="list", aria-multiline) controlling a listbox; the highlighted person is announced through aria-activedescendant.
- Keyboard: Down / Up move through people, Enter or Tab insert, Esc closes the list and keeps the text; Backspace after a token removes the whole name.
- Each inserted mention is announced in a polite live region. The visible text is the real text, so screen readers read "@Name" naturally.
- People rows are 44px. Reduced motion removes the list and token glow animations.
Motion
The list scales in from 0.96 and 4px above in 200ms ease-out. A new token starts with a stronger tint and a 4px glow that settle over 360ms. The field turns white with a halo in 220ms.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
MentionInput.jsxmention-input.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.







