React Mentions Component

2.20.0 · active · verified Sun Apr 19

rc-mentions is a foundational React component designed for building rich `@`-mentions input functionalities within web applications. It provides the core logic and UI structure for user mentions, offering a highly customizable experience without dictating specific styling. The current stable version, `2.20.0`, is actively maintained, with frequent minor and patch releases indicated by the project's recent activity, though specific release notes for major version `2` are not immediately visible in the provided data. Key differentiators include its broad browser compatibility (supporting IE9+, Chrome, Firefox, Safari), robust keyboard navigation for accessibility, and a flexible API that allows developers full control over filtering options and popup placement. Unlike opinionated UI libraries, `rc-mentions` ships unstyled, requiring developers to provide their own CSS (typically from its Less source) for integration into their design system.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates basic usage of `rc-mentions`, showing how to import the component, its required styles, define options, and render it in a React application. It includes placeholder text and simple `onSelect`/`onChange` handlers.

import React from 'react';
import ReactDOM from 'react-dom';
import Mentions from 'rc-mentions';
import 'rc-mentions/assets/index.less'; // Ensure your build system handles Less files

const { Option } = Mentions;

const MentionsDemo = () => (
  <Mentions
    placeholder="Mention users here..."
    style={{ width: '100%' }}
    onSelect={(option, prefix) => console.log(`Selected ${option.value} with prefix ${prefix}`)}
    onChange={(value) => console.log('Current value:', value)}
  >
    <Option value="light">Light</Option>
    <Option value="bamboo">Bamboo</Option>
    <Option value="cat">Cat</Option>
    <Option value="dog">Dog</Option>
    <Option value="elephant">Elephant</Option>
    <Option value="fox">Fox</Option>
  </Mentions>
);

const container = document.getElementById('root') || document.createElement('div');
if (!document.getElementById('root')) {
  container.id = 'root';
  document.body.appendChild(container);
}

ReactDOM.render(<MentionsDemo />, container);

view raw JSON →