Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Mention Input

A text field that suggests people, channels or tags in a popup when a trigger character such as `@` is typed, and inserts the chosen one into the text.

Built on the headless Mention Input.See its API in Docs

Rendered by React 19.3.1

mention-input.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/mention-input.json

It also adds utils. The app needs its setup first: Installation.

Usage

Put a MentionInputInput (a <textarea>) and MentionInputPortal > MentionInputPositioner > MentionInputPopup in MentionInput, and a MentionInputList of MentionInputItems in the Popup, with an optional MentionInputEmpty for a query that matches nothing. MentionInputCollection renders an Item for each matching item, and MentionInputGroup with a MentionInputGroupLabel heads a group of them. The popup opens at the trigger character; the Items it lists follow the text typed after the trigger. trigger takes one character or a list (['@', '#']), items, itemToStringValue, itemToInsertText and insertSuffix say what is listed and inserted, and value, onValueChange, onItemInsert, labels and the rest come from the headless Mention Input.

import {
  MentionInput,
  MentionInputArrow,
  MentionInputCollection,
  MentionInputEmpty,
  MentionInputGroup,
  MentionInputGroupLabel,
  MentionInputInput,
  MentionInputItem,
  MentionInputList,
  MentionInputPopup,
  MentionInputPortal,
  MentionInputPositioner,
  MentionInputRow,
  MentionInputSeparator,
} from '@/components/ui/mention-input'

Examples

Default

A comment box that mentions teammates with @.

Its preview and code are at the top of the page.

Triggers

@ for people and # for channels in one field, each with its own items.

Rendered by React 19.3.1

mention-input-triggers.tsx

The Input is the Textarea's, growing with its text. The popup is the Combobox's, 256 CSS pixels wide, placed under the trigger character 4 CSS pixels below its line; the highlighted Item takes the accent background. Arrow Up and Arrow Down move the highlight while the popup is open, Enter inserts the highlighted Item, and Escape closes the popup and keeps the text as typed. A status region announces how many suggestions there are and which one was inserted, in the words labels gives. Give the Input a label (WCAG 1.3.1, 4.1.2), as for any field. This item takes Base UI's component ID as its slug and one name per Base UI part.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Mention Input's API reference.