Mention Input
NewComment box with @mentions: suggestions as you type, keyboard picking, who will be notified, and Ctrl/⌘+Enter to send.
Installation
$ pnpm dlx shadcn@latest add @synccn/mention-inputFirst time in this project? Connect synccn with one command.
Usage
import { MentionInput, extractMentions } from "@/components/ui/mention-input";<MentionInput people={team} onSubmit={(text, mentioned) => …} />API reference
Generated from the component's TypeScript types, so it always matches the code.
MentionInput
Textarea with
- peoplerequired
MentionPerson[]People who can be mentioned.
- value
stringControlled text.
- defaultValue
stringDefault
""Text at first, when uncontrolled.
- onValueChange
(value: string) => voidCalled with the text on every change.
- onSubmit
(value: string, mentioned: MentionPerson[]) => voidCalled with the text and mentioned people on Ctrl/⌘+Enter. Shows a send hint when set.
- trigger
stringDefault
"@"Character that starts a mention.
- maxSuggestions
numberDefault
6Suggestions shown at once.
- placeholder
stringPlaceholder text.
- rows
numberDefault
3Visible lines.
- aria-label
stringAccessible name.
extractMentions
People whose `@Name` appears in the text, in the order they're first mentioned.
Takes no props.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for AtSign, CornerDownLeft
Keyboard
- ↓or↑Move through suggestions
- EnterorTabInsert the suggestion
- EscClose suggestions
- Ctrl+Enteror⌘EnterSend
Accessibility
- The textarea is a combobox that points at the active suggestion with aria-activedescendant.
- Who will be notified is shown in text under the field.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: combobox, listbox, option
- ARIA attributes: aria-activedescendant, aria-autocomplete, aria-controls, aria-expanded, aria-label, aria-selected
- Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Home, End, Enter, Escape, Tab