React Native · Components
MentionInput
Mention input (same API as MentionInput on web): typing @ suggests people, # tags…; the selected name is highlighted in the box and stored in the value as @[Jane Doe](u1).
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
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
MentionInput
componentMention input (same API as MentionInput on web): typing @ suggests people, # tags…; the selected name is highlighted in the box and stored in the value as @[Jane Doe](u1).
- Highlight: Mentions show colored inside the text field (the same on both platforms); deleting removes the whole mention, and typing inside one turns it back into plain text.
- Suggestions: An array is filtered ignoring Turkish letter case; with a function it searches the server (150 ms wait, old requests cancelled). The list is below the box; in a chat box use
suggestionsPlacement="above". - Chat: With
onSubmitthe keyboard's send key sends. - Form: The stored format binds inside a
Formwithname.
To show a stored value use MentionView; to parse it on the server use parseMentions.
Examples
MentionView
componentShows text written with MentionInput: line breaks are kept, mentions are highlighted and optionally tappable.
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)").
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. |
MentionItem
interfaceAn item in the MentionInput suggestions (same as web).
| 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 | A small description below 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 (same as web).
| Name | Type | Default | Description |
|---|---|---|---|
trigger | string | Trigger character: "@" people, "#" tags, ":" emoji… | |
items | readonly MentionItem[] | ((query: string, signal: AbortSignal) => Promise<readonly MentionItem[]> | readonly MentionItem[]) | Suggestions: an array (searched in the name, description and keywords ignoring Turkish letter case) or a function called with the typed query (server-side search; old requests are cancelled via signal, with a 150 ms wait). | |
label? | ReactNode | Title of the list (e.g. "People"). | |
allowSpaces? | boolean | true | Allow spaces in the query (e.g. "@Jane Do")? |
renderItem? | (item: MentionItem) => ReactNode | Your own content in place of a row in the list. |
Extra info passed on a MentionInput value change.
MentionInputProps
interfaceProps of MentionInput (same names as on web).
Extends: FieldProps
| Name | Type | Default | Description |
|---|---|---|---|
ref? | Ref<TextInputRef> | Ref of the underlying text input. | |
sources | MentionSource | readonly MentionSource[] | Triggers and their suggestions: a single source or an array. | |
value? | string | Controlled value: plain text, mentions in the form @[Jane Doe](u1). | |
defaultValue? | string | Initial value in uncontrolled use. | |
onValueChange? | (value: string, details: MentionChangeDetails) => void | When the value changes, with the stored format and plain text + a list of mentions. | |
onMentionAdd? | (item: MentionItem, trigger: string) => void | When a suggestion is selected. | |
multiline? | boolean | true | Multiline? |
rows? | number | 3 | Minimum rows when multiline. |
autoResize? | boolean | true | Grow while typing (up to maxRows)? |
maxRows? | number | 8 | Maximum rows with autoResize; then it scrolls inside. |
onSubmit? | (value: string, details: MentionChangeDetails) => void | Called with the keyboard's send key; when given, the key sends instead of adding a line even when multiline (like a chat box). | |
placeholder? | string | Text shown when empty. | |
appendSpace? | boolean | true | Add a space after a selected mention? |
limit? | number | 50 | Maximum suggestions in the list. |
suggestionsPlacement? | "below" | "above" | "below" | Position of the suggestion list. For boxes at the bottom of the screen (chat) use "above": the list stays visible while the keyboard is open. |
variant? | FieldVariant | "outline" | Field appearance. |
maxLength? | number | Maximum characters (visible text). | |
readOnly? | boolean | Read-only. | |
autoFocus? | boolean | Focuses when the screen opens. | |
aria-label? | string | Screen reader name; give it when there is no visible label. | |
onBlur? | (event: TextInputFocusEvent) => void | On blur. | |
style? | StyleProp<ViewStyle> | Container style. |
MentionViewProps
interfaceProps of MentionView.
| Name | Type | Description |
|---|---|---|
value | string | The stored value ("Hello @[Jane Doe](u1)"). |
triggers? | readonly string[] | Only these triggers count as mentions. If omitted, all. |
onMentionPress? | (mention: MentionEntity) => void | When a mention is tapped (e.g. go to the profile screen). When given, the mention is read as a link. The counterpart of getHref on web. |
renderMention? | (mention: MentionEntity) => ReactNode | Your own content in place of a mention (must be an inline Text). |
style? | StyleProp<TextStyle> | Text style. |
mentionStyle? | StyleProp<TextStyle> | Style of the mentions. |
numberOfLines? | number | Maximum lines; the rest is cut off with …. |