structyl

Mentions API

View component

The full prop reference for the Mentions component. A textarea with @-mention autocomplete.

Import

tsx
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.

PropTypeDefault
value#string

Controlled text value of the mentions textarea

—
defaultValue#string

Default uncontrolled initial value

''
onValueChange#(value: string) => void

Callback fired when the textarea value changes

—
triggerChar#string

Character that triggers mention suggestions (e.g., '@' for people, '#' for tags)

'@'
asChild#boolean

Whether to render the component as its single child instead of a div wrapper

—
className#string

CSS 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.

PropTypeDefault
onChange#(event: React.ChangeEvent<HTMLTextAreaElement>) => void

Native textarea onChange handler (composed with internal mention logic)

—
onKeyDown#(event: React.KeyboardEvent<HTMLTextAreaElement>) => void

Native textarea onKeyDown handler (composed with arrow key and escape navigation)

—
className#string

CSS class names to apply to the textarea element

—
placeholder#string

Placeholder 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.

PropTypeDefault
items#MentionSuggestion[]

Array of suggestion objects with id and label properties to filter and display

—
container#Element | DocumentFragment | null

Portal container element; if not provided, portals to document.body

—
className#string

CSS class names to apply to the wrapper div element

—
children#React.ReactNode

Child 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.

PropTypeDefault
children#(item: MentionSuggestion, index: number, highlighted: boolean) => React.ReactNode

Render 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.

PropTypeDefault
suggestion#MentionSuggestion

The suggestion object with id and label to be inserted when selected

—
index#number

The index of this item in the filtered suggestions list

—
children#React.ReactNode

Content to render inside the item; defaults to suggestion.label if not provided

—
onClick#(event: React.MouseEvent<HTMLDivElement>) => void

Native click handler (composed with suggestion selection logic)

—
onPointerMove#(event: React.PointerEvent<HTMLDivElement>) => void

Native pointer move handler (composed with highlight logic)

—
className#string

CSS class names to apply to the item div

—

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library