Mentions API
View componentThe full prop reference for the Mentions component. A textarea with @-mention autocomplete.
Import
import { Mentions } from '@structyl/styled';Props
Root
Container component that manages mentions state and provides context to child components. Supports controlled/uncontrolled value and custom trigger characters.
| Prop | Type | Default |
|---|---|---|
| value# | stringControlled text value of the mentions textarea | — |
| defaultValue# | stringDefault uncontrolled initial value | '' |
| onValueChange# | (value: string) => voidCallback fired when the textarea value changes | — |
| triggerChar# | stringCharacter that triggers mention suggestions (e.g., '@' for people, '#' for tags) | '@' |
| asChild# | booleanWhether to render the component as its single child instead of a div wrapper | — |
| className# | stringCSS class names to apply to the root div element | — |
Textarea
Textarea input that manages caret position detection, query tracking, and keyboard navigation (arrow keys, escape). Automatically handles mention trigger detection and suggestion filtering.
| Prop | Type | Default |
|---|---|---|
| onChange# | (event: React.ChangeEvent<HTMLTextAreaElement>) => voidNative textarea onChange handler (composed with internal mention logic) | — |
| onKeyDown# | (event: React.KeyboardEvent<HTMLTextAreaElement>) => voidNative textarea onKeyDown handler (composed with arrow key and escape navigation) | — |
| className# | stringCSS class names to apply to the textarea element | — |
| placeholder# | stringPlaceholder text shown when textarea is empty | — |
Suggestions
Container for filtered mention suggestions. Renders suggestions in a portal by default unless disablePortal is true. Handles visibility based on open state and filtered items.
| Prop | Type | Default |
|---|---|---|
| items# | MentionSuggestion[]Array of suggestion objects with id and label properties to filter and display | — |
| container# | Element | DocumentFragment | nullPortal container element; if not provided, portals to document.body | — |
| className# | stringCSS class names to apply to the wrapper div element | — |
| children# | React.ReactNodeChild elements (typically a div containing Items component) | — |
Items
Render prop component that iterates over filtered suggestions and calls the render function for each item with access to the item, index, and highlighted state.
| Prop | Type | Default |
|---|---|---|
| children# | (item: MentionSuggestion, index: number, highlighted: boolean) => React.ReactNodeRender function called for each filtered suggestion item with the item data, its index, and boolean indicating if it's currently highlighted | — |
Item
Individual suggestion item component. Handles click selection, pointer move highlighting, and semantic option role for accessibility.
| Prop | Type | Default |
|---|---|---|
| suggestion# | MentionSuggestionThe suggestion object with id and label to be inserted when selected | — |
| index# | numberThe index of this item in the filtered suggestions list | — |
| children# | React.ReactNodeContent to render inside the item; defaults to suggestion.label if not provided | — |
| onClick# | (event: React.MouseEvent<HTMLDivElement>) => voidNative click handler (composed with suggestion selection logic) | — |
| onPointerMove# | (event: React.PointerEvent<HTMLDivElement>) => voidNative pointer move handler (composed with highlight logic) | — |
| className# | stringCSS class names to apply to the item div | — |
Source code
If you didn't find what you need here, read the component implementation .