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
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | '' | Controlled value of the textarea |
onChange | (value: string) => void | — | Callback when value changes |
onMention | (option: MentionOption) => void | — | Callback when a mention is selected |
options | MentionOption[] | [] | Available mention options |
trigger | string | '@' | Character that triggers the dropdown |
placeholder | string | — | Placeholder text |
rows | number | 4 | Number of visible text rows |
disabled | boolean | false | Disable the input |
className | string | — | Additional CSS classes |
MentionOption Type
| Prop | Type | Default | Description |
|---|---|---|---|
id* | string | — | Unique identifier for the option |
display* | string | — | Display text for the mention |
avatar | string | — | Optional avatar image URL |
metadata | Record<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 selectionKeyboard Navigation
| Key | Action |
|---|---|
| Type trigger | Open mention dropdown |
| Arrow Up/Down | Navigate options |
| Enter | Select highlighted option |
| Escape | Close 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