Skip to content

Mention

Mention is a text field (or textarea) that suggests options after a prefix such as @. Typing the prefix at the start or after a space opens a menu under it; the text between the prefix and the caret filters the options, and picking one inserts prefix + value + separator. It is built on Input, and shares its option list with Select. Focus stays in the field, which drives the list with aria-activedescendant: a text input is the combobox of the WAI-ARIA combobox pattern; a textarea stays a multiline textbox, since HTML doesn’t allow it the combobox role.

Demos

Basic

Type @ to open the menu at the @. A prefix inside a word (like an email address) doesn’t open it. Typing the separator (a space by default), moving the caret out of the mention, Escape or leaving the field closes it. Disabled options are skipped.

Textarea

type="textarea" uses a textarea; autosize and rows work as in Input. The menu opens under the line with the prefix, also after the textarea has scrolled. A line break ends a mention.

Several prefixes

prefix takes an array. onSearch and onSelect tell you which prefix was typed, so you can pass different options for each.

onSearch(pattern, prefix) is called whenever the mention being typed changes; fetch the options there. While loading, the menu shows a spinner.

Keyboard

While the menu is open: ↑ / ↓ move the active option (skipping disabled ones and wrapping); Enter or Tab inserts it; Escape closes the menu until you type again. Everything else edits the text. Enter and Tab are only taken when there is an option to insert; Mention handles keys before your onKeyDown, so check event.defaultPrevented there (for example before sending a message on Enter).

Props

NameTypeDefaultDescriptionVersion
optionsMentionMixedOption[]requiredOptions { label, value, disabled? }, optionally in groups { type: "group", label, key, children }. value is what gets inserted.Unreleased
valuestring | nullundefinedControlled text.Unreleased
defaultValuestring""Initial text when uncontrolled.Unreleased
onUpdateValue(value: string) => voidundefinedCalled with the new text on every edit and pick.Unreleased
prefixstring | string[]"@"What starts a mention.Unreleased
separatorstring" "Inserted after a picked option; typing it ends a mention.Unreleased
typetext | textareatextA single-line input or a textarea.Unreleased
autosize / rowsTextarea sizing, as in Input.Unreleased
filter(pattern, option) => booleanlabel or value containsWhether an option matches the typed pattern (case-insensitive by default).Unreleased
onSearch(pattern: string, prefix: string) => voidundefinedCalled when the mention being typed changes.Unreleased
onSelect(option, prefix: string) => voidundefinedCalled after an option is inserted.Unreleased
renderLabel(option) => ReactNodeundefinedCustom label in the menu.Unreleased
loadingbooleanfalseThe menu shows a spinner instead of options.Unreleased
emptyReactNodelocale “No data”Shown when no option matches.Unreleased
placeholderstringundefinedShown when empty.Unreleased
sizetiny | small | medium | largemediumField height and text size.Unreleased
statussuccess | warning | errorundefinedBorder color.Unreleased
disabledbooleanfalseCan’t be edited.Unreleased
placementPopoverPlacementbottom-startWhere the menu opens, relative to the prefix.Unreleased
to / zIndexSame as Popover.Unreleased
onFocus / onBlur(event) => voidundefinedFocus entering / leaving the field.Unreleased

Other Input props are forwarded: className, style and wrapperRef go to the bordered box; ref, id, aria-*, onKeyDown and other native attributes to the input or textarea. Mention’s prefix and loading replace Input’s affix and spinner.