Skip to content
synccn

Mention Input

New

Comment box with @mentions: suggestions as you type, keyboard picking, who will be notified, and Ctrl/⌘+Enter to send.

Notifies synccn

Installation

$ pnpm dlx shadcn@latest add @synccn/mention-input

First 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
    string

    Controlled text.

  • defaultValue
    string

    Default ""

    Text at first, when uncontrolled.

  • onValueChange
    (value: string) => void

    Called with the text on every change.

  • onSubmit
    (value: string, mentioned: MentionPerson[]) => void

    Called with the text and mentioned people on Ctrl/⌘+Enter. Shows a send hint when set.

  • trigger
    string

    Default "@"

    Character that starts a mention.

  • maxSuggestions
    number

    Default 6

    Suggestions shown at once.

  • placeholder
    string

    Placeholder text.

  • rows
    number

    Default 3

    Visible lines.

  • aria-label
    string

    Accessible 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.

Helpers

  • lib/hooksuseControllable (works controlled or uncontrolled)
  • lib/utilscn (merges class names)

npm packages

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