Mentions

Forms
Social

Textarea input with @mentions, #hashtags, and other triggers for autocomplete suggestions. Ideal for comments, messages, and collaborative editing.

Preview

Type @ to trigger user mentions

Type @ to mention

With Avatars

Display user avatars in dropdown for visual recognition

Type @ to mention

Hashtag Trigger

Use # to trigger tag suggestions

Type # to mention

Channel References

Reference channels with # for Slack-like mentions

Type # to mention

Multi-line Input

Works with larger text areas

Type @ to mention

Props

Mentions component API reference

PropTypeDefaultDescription
valuestring''Controlled value of the textarea
onChange(value: string) => voidCallback when value changes
onMention(option: MentionOption) => voidCallback when a mention is selected
optionsMentionOption[][]Available mention options
triggerstring'@'Character that triggers the dropdown
placeholderstringPlaceholder text
rowsnumber4Number of visible text rows
disabledbooleanfalseDisable the input
classNamestringAdditional CSS classes

MentionOption Type

PropTypeDefaultDescription
id*stringUnique identifier for the option
display*stringDisplay text for the mention
avatarstringOptional avatar image URL
metadataRecord<string, any>Optional additional data

Usage

Import and implementation example

import { Mentions, type MentionOption } from '@/components/ui/mentions'

const users: MentionOption[] = [
  { id: '1', display: 'Alice Johnson', avatar: '/avatars/alice.jpg' },
  { id: '2', display: 'Bob Smith', avatar: '/avatars/bob.jpg' },
  { id: '3', display: 'Carol Williams', avatar: '/avatars/carol.jpg' },
]

const tags: MentionOption[] = [
  { id: 'bug', display: 'bug' },
  { id: 'feature', display: 'feature' },
]

export default function Example() {
  const [value, setValue] = useState('')

  return (
    <>
      {/* User mentions with @ trigger */}
      <Mentions
        value={value}
        onChange={setValue}
        options={users}
        placeholder="Type @ to mention someone..."
        onMention={(option) => console.log('Mentioned:', option)}
      />

      {/* Tag mentions with # trigger */}
      <Mentions
        value={value}
        onChange={setValue}
        options={tags}
        trigger="#"
        placeholder="Add tags with #..."
      />

      {/* Multi-line with more rows */}
      <Mentions
        options={users}
        placeholder="Write a longer message..."
        rows={6}
      />
    </>
  )
}
This block is self-contained (no UI component dependencies)

Features

Built-in functionality

  • Customizable trigger: Use @ for users, # for tags, or any character
  • Avatar support: Display user avatars in dropdown
  • Real-time filtering: Filter options as you type after trigger
  • Keyboard navigation: Arrow keys and Enter to select
  • Multi-line support: Configurable number of rows
  • Mention callback: Get notified when mentions are selected
  • Metadata support: Attach custom data to options
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

Textarea is properly labeledDropdown uses role="listbox"Options use role="option"aria-activedescendant tracks selection

Keyboard Navigation

KeyAction
Type triggerOpen mention dropdown
Arrow Up/DownNavigate options
EnterSelect highlighted option
EscapeClose dropdown

Notes

  • Focus remains in textarea while navigating
  • Selected mention is inserted at cursor position
  • Dropdown positions automatically based on space
  • Avatar images have alt text for screen readers