Mentions
Multi-line input with @-prefixed member suggestions; selecting writes the mention back into the text.
Basic usage
Basic usage
Mentioned:—
import { useState } from 'react'
import { LhMentions } from '@lh-ui/react'
const members = [
{ label: 'Alice', value: 'alice' },
{ label: 'Bob', value: 'bob' },
]
export default function Demo() {
const [text, setText] = useState('')
return <LhMentions options={members} onValueChange={setText} />
}
Mentions Props
| Prop | Description | Type | Values | Default |
|---|---|---|---|---|
| options | Candidate members | MentionOption[] | — | [] |
| value | Text value (controlled) | string | — | — |
| defaultValue | Default text value (uncontrolled) | string | — | — |
| onValueChange | Text change callback | (value: string) => void | — | — |
| onSelect | Candidate selected (second arg is the full text after insertion) | (option, insertText) => void | — | — |
| prefix | Trigger prefix | string | — | '@' |
| rows | Textarea rows | number | — | 3 |
| disabled | Disabled | boolean | — | false |
| name | Native form name (hidden input) | string | — | — |
| placeholder / ariaLabel / sx | Common props | — | — | — |
MentionOption: { label: string; value?: string; disabled?: boolean }. The human-readable @label is written back to the text; the machine value reaches the app via onSelect.
Mentions Events
| Event | Description | Callback | Vue equivalent |
|---|---|---|---|
| onValueChange | Text change | (value: string) => void | @input |
| onSelect | Candidate selected | (option, insertText) => void | @select |
Context rules
The panel activates when the caret finds the nearest prefix with no whitespace between it and the caret. Email-like pseudo prefixes (a@b.com, preceded by ASCII alphanumeric / ._%+-) do not trigger. CJK characters adjacent to the prefix (你好@张三) trigger normally.
Keyboard interaction
While the panel is open, ArrowUp / ArrowDown move the highlight and Enter selects the suggestion (no line break); Esc closes. The input exposes combobox aria attributes.
Styles
import '@lh-ui/react/style/mentions'