Web · Components
MentionInput
Mention box: typing @ opens suggestions like people, # like tags; the selected item is added to the text highlighted.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
In a form and showing what was saved
@Ayşe Yılmaz the design is ready for #release. @Çağrı Demir the mobile side is yours.
Import
Mention box: typing @ opens suggestions like people, # like tags; the selected item is added to the text highlighted. For plain text fields like comments, chat messages and task descriptions. For rich text use RichTextEditor mentions.
- Value: plain text; mentions are stored as
@[Ayşe Yılmaz](u1)and show as@Ayşe Yılmazin the box. On the server get the mentioned ones withparseMentionsand show them withMentionView. - Suggestions: an array (filtered ignoring case and accents, Turkish-aware, with prefix matches first) or a function searching the server (150 ms debounce, aborts old requests). The list opens below the caret and moves above it if it doesn't fit on screen.
- Keyboard: ↑/↓ navigate, Enter or Tab selects, Esc closes. Backspace right after a mention deletes it as a whole; typing inside turns it into plain text.
- Chat box: with
onSubmitEnter submits and Shift+Enter adds a new line;multiline={false}for a single line. - Form: with
namethe stored format is submitted;requiredandmaxLengthwork. For labeled use seeMentionField.
Examples
Shows text written with MentionInput: line breaks are kept and mentions are highlighted (optionally linked). It is a server component.
Examples
parseMentions
functionSplits a stored value ("Hello @[Jane Doe](u1)") into plain text and a list of mentions. Used on the server to notify the mentioned people.
Examples
serializeMentions
functionBuilds the stored value from plain text and mentions (e.g. "@[Jane](u1)").
MentionItem
interfaceAn item in the MentionInput suggestions.
| Name | Type | Description |
|---|---|---|
id | string | Id; stored in the value (@[Name](id)). |
label | string | Display name (without the trigger); this is written into the box. |
description? | ReactNode | Small description under the name (e.g. an email, a channel topic). |
avatar? | string | Avatar image URL. |
icon? | IconProp | Icon instead of an avatar. |
disabled? | boolean | Cannot be selected. |
keywords? | readonly string[] | Extra words that should match in search (e.g. a username). |
MentionSource
interfaceA trigger and its suggestions for MentionInput.
| Name | Type | Default | Description |
|---|---|---|---|
trigger | string | Trigger character: "@" people, "#" channels/tags, ":" emoji… | |
items | readonly MentionItem[] | ((query: string, signal: AbortSignal) => Promise<readonly MentionItem[]> | readonly MentionItem[]) | Suggestions: an array (searched case-insensitively, Turkish-aware, in the name, description and keywords) or a function called with the typed query (server search; old requests are aborted via signal, with a 150 ms debounce). | |
label? | ReactNode | Title of the list (e.g. "People"). | |
allowSpaces? | boolean | true | Allow spaces in the search (e.g. "@Ayşe Yıl")? |
renderItem? | (item: MentionItem) => ReactNode | Your own content instead of the row in the list. |
MentionChangeDetails
interfaceExtra info that comes with a MentionInput value change.
| Name | Type | Description |
|---|---|---|
text | string | Plain text shown in the box ("Hello @Ayşe"). |
mentions | MentionEntity[] | Mentions in the text. |
MentionInputClassNames
interfaceClasses that can be passed to the inner parts of MentionInput.
| Name | Type | Description |
|---|---|---|
input? | string | Text area. |
list? | string | Suggestion list. |
mention? | string | Mention highlight in the text. |
MentionInputProps
interfaceProps of the MentionInput component.
| Name | Type | Default | Description |
|---|---|---|---|
sources | MentionSource | readonly MentionSource[] | Triggers and their suggestions. For a single source { trigger: "@", items }, for several an array (e.g. @ people, # tags). | |
value? | string | Value when controlled: plain text, with mentions in the form @[Ayşe Yılmaz](u1). On the server parse it with parseMentions. | |
defaultValue? | string | Initial value when uncontrolled. | |
onValueChange? | (value: string, details: MentionChangeDetails) => void | Called with the stored format and the plain text + mention list when the value changes. | |
onMentionAdd? | (item: MentionItem, trigger: string) => void | When a suggestion is selected. | |
multiline? | boolean | true | Multi-line? If false, a single line (Enter doesn't add a line; onSubmit is called). |
rows? | number | 3 | Minimum number of lines when multi-line. |
autoResize? | boolean | true | Grow as you type (limit it with a max-h-* class)? |
onSubmit? | (value: string, details: MentionChangeDetails) => void | Called when Enter is pressed (while the suggestion list is closed); if given, a new line is added with Shift+Enter in multi-line mode (like a chat box). | |
placeholder? | string | Text shown when empty. | |
appendSpace? | boolean | true | Add a space after a selected mention? |
limit? | number | 50 | Maximum number of suggestions shown in the list. |
variant? | FieldVariant | CustomVariant<"field"> | Appearance. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
name? | string | Form field name; the value in the stored format is submitted under this name. | |
form? | string | Id of the form the field belongs to. | |
required? | boolean | Cannot be submitted empty. | |
maxLength? | number | Maximum characters (of the visible text). | |
disabled? | boolean | Disabled. | |
readOnly? | boolean | Read-only. | |
id? | string | Id of the text area. | |
autoFocus? | boolean | Focused when the page opens. | |
tooltip? | TooltipProp | Hint shown when hovering the box. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | MentionInputClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name. | |
aria-labelledby? | string | Id of the element naming the field. | |
aria-describedby? | string | Id of the element describing the field. | |
aria-invalid? | boolean | "true" | "false" | Show as invalid. |
MentionViewProps
interfaceProps of the MentionView component.
| Name | Type | Description |
|---|---|---|
value | string | The stored value ("Hello @[Ayşe Yılmaz](u1)"). |
triggers? | readonly string[] | Only these triggers count as mentions. If omitted, all. |
getHref? | (mention: MentionEntity) => string | undefined | Link of the mention (e.g. a profile page). If given, the mention is rendered as an <a>. |
renderMention? | (mention: MentionEntity) => ReactNode | Your own content instead of the mention (e.g. a person card with HoverCard). |
className? | string | Classes added to the container. |
mentionClassName? | string | Classes added to the mentions. |
MentionEntity
interfaceA mention in the text. Stored in the value as @[Jane Doe](u1); shown in the box as @Jane Doe.
| Name | Type | Description |
|---|---|---|
trigger | string | Trigger character ("@", "#"…). |
id | string | Id (e.g. user id). |
label | string | Display name (without the trigger). |
start | number | Start in the displayed text (including the trigger). |
end | number | End in the displayed text (exclusive). |
ParsedMentions
interfaceResult of parseMentions.
| Name | Type | Description |
|---|---|---|
text | string | Plain text shown in the box ("Hello @Jane Doe"). |
mentions | MentionEntity[] | Mentions in the text, in order. |