Socket
Socket
Sign inDemoInstall

rc-mentions

Package Overview
Dependencies
19
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-mentions

React Mentions


Version published
Weekly downloads
1.2M
increased by7.89%
Maintainers
3
Install size
1.51 MB
Created
Weekly downloads
 

Package description

What is rc-mentions?

The rc-mentions npm package is designed to provide a React component for implementing mention features within applications. It allows users to easily mention people, tags, or other entities in text inputs or textareas by typing a trigger character (like '@') followed by a list of suggestions.

What are rc-mentions's main functionalities?

Basic Mentioning

This feature allows for basic mentioning functionality where users can type '@' followed by a list of predefined suggestions. The code sample demonstrates how to set up a basic Mention component with a default value and a list of suggestions.

import React from 'react';
import Mention from 'rc-mentions';
const { Option } = Mention;

function App() {
  return (
    <Mention
      style={{ width: '100%' }}
      defaultValue="@afc163"
      suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
    />
  );
}

Custom Trigger

This feature allows users to customize the trigger character for mentions. In this example, both '@' and '#' are set as triggers, enabling mentions for users as well as tags or other entities.

import React from 'react';
import Mention from 'rc-mentions';
const { Option } = Mention;

function App() {
  return (
    <Mention
      style={{ width: '100%' }}
      prefix={['@', '#']}
      suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
    />
  );
}

Custom Render

This feature allows for custom rendering of suggestions. The code sample shows how to use the Option component to customize how suggestions are displayed, providing more flexibility in the presentation of suggestions.

import React from 'react';
import Mention from 'rc-mentions';
const { Option } = Mention;

function App() {
  return (
    <Mention
      style={{ width: '100%' }}
      suggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご'].map(value => (
        <Option key={value} value={value}>
          {value}
        </Option>
      ))}
    />
  );
}

Other packages similar to rc-mentions

Readme

Source

rc-mentions

NPM version npm download build status Codecov bundle size dumi

Screenshots

Feature

  • support ie9,ie9+,chrome,firefox,safari

Keyboard

  • Open mentions (focus input || focus and click)
  • KeyDown/KeyUp/Enter to navigate menu

install

rc-mentions

Usage

basic use

/**
 * inline: true
 */
import Mentions from 'rc-mentions';

const { Option } = Mentions;

var Demo = (
  <Mentions>
    <Option value="light">Light</Option>
    <Option value="bamboo">Bamboo</Option>
    <Option value="cat">Cat</Option>
  </Mentions>
);
React.render(<Demo />, container);

API

Mentions props

namedescriptiontypedefault
autoFocusAuto get focus when component mountedbooleanfalse
defaultValueDefault valuestring-
filterOptionCustomize filter option logicfalse | (input: string, option: OptionProps) => boolean-
notFoundContentSet mentions content when not matchReactNode'Not Found'
placementSet popup placement'top' | 'bottom''bottom'
directionSet popup direction'ltr' | 'rtl''ltr'
prefixSet trigger prefix keywordstring | string[]'@'
rowsSet row countnumber1
splitSet split string before and after selected mentionstring' '
validateSearchCustomize trigger search logic(text: string, props: MentionsProps) => void-
valueSet value of mentionsstring-
onChangeTrigger when value changed(text: string) => void-
onKeyDownTrigger when user hits a keyReact.KeyboardEventHandler<HTMLTextAreaElement>-
onKeyUpTrigger when user releases a keyReact.KeyboardEventHandler<HTMLTextAreaElement>-
onSelectTrigger when user select the option(option: OptionProps, prefix: string) => void-
onSearchTrigger when prefix hit(text: string, prefix: string) => void-
onFocusTrigger when mentions get focusReact.FocusEventHandler<HTMLTextAreaElement>-
onBlurTrigger when mentions lose focusReact.FocusEventHandler<HTMLTextAreaElement>-
getPopupContainerDOM Container for suggestions() => HTMLElement-
autoSizeTextarea height autosize feature, can be set to true|false or an object { minRows: 2, maxRows: 6 }boolean | object-
onPressEnterThe callback function that is triggered when Enter key is pressedfunction(e)-
onResizeThe callback function that is triggered when textarea resizefunction({ width, height })-

Methods

namedescription
focus()Component get focus
blur()Component lose focus

Development

npm install
npm start

Example

http://localhost:9001/

online example: http://react-component.github.io/mentions/

Test Case

npm test

Coverage

npm run coverage

License

rc-mentions is released under the MIT license.

Keywords

FAQs

Last updated on 08 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc