├── .babelrc.js ├── .changeset ├── README.md └── config.json ├── .eslintrc ├── .github ├── codeql │ └── codeql-config.yml └── workflows │ ├── codeql.yml │ ├── release.yml │ └── tests.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .reuse └── dep5 ├── .vscode └── settings.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── LICENSES └── Apache-2.0.txt ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── demo ├── src │ ├── examples │ │ ├── Advanced.js │ │ ├── AsyncGithubUserMentions.js │ │ ├── BottomGuard.js │ │ ├── CssModules.js │ │ ├── CustomInputComponent.js │ │ ├── CustomSuggestionsContainer.js │ │ ├── CutCopyPaste.js │ │ ├── Emojis.js │ │ ├── Examples.js │ │ ├── MultipleTrigger.js │ │ ├── Scrollable.js │ │ ├── SingleLine.js │ │ ├── SingleLineIgnoringAccents.js │ │ ├── SuggestionPortal.js │ │ ├── defaultMentionStyle.js │ │ ├── defaultStyle.js │ │ ├── emojiExampleStyle.js │ │ ├── example.module.css │ │ ├── higher-order │ │ │ ├── index.js │ │ │ └── provideExampleValue.js │ │ ├── hooks │ │ │ ├── index.js │ │ │ └── useExampleValue.js │ │ └── index.js │ ├── index.html │ └── index.js └── webpack.config.js ├── jest.config.js ├── jest └── setupTestFramework.js ├── now.json ├── nwb.config.js ├── package.json ├── src ├── Highlighter.js ├── Highlighter.spec.js ├── LoadingIndicator.js ├── Mention.js ├── MentionsInput.js ├── MentionsInput.spec.js ├── Suggestion.js ├── Suggestion.spec.js ├── SuggestionsOverlay.js ├── SuggestionsOverlay.spec.js ├── __snapshots__ │ └── MentionsInput.spec.js.snap ├── index.js └── utils │ ├── applyChangeToValue.js │ ├── applyChangeToValue.spec.js │ ├── combineRegExps.js │ ├── combineRegExps.spec.js │ ├── countPlaceholders.js │ ├── countSuggestions.js │ ├── defaultStyle.js │ ├── diacritics.js │ ├── escapeRegex.js │ ├── findPositionOfCapturingGroup.js │ ├── findPositionOfCapturingGroup.spec.js │ ├── findStartOfMentionInPlainText.js │ ├── findStartOfMentionInPlainText.spec.js │ ├── getEndOfLastMention.js │ ├── getEndOfLastMention.spec.js │ ├── getMentions.js │ ├── getMentions.spec.js │ ├── getPlainText.js │ ├── getPlainText.spec.js │ ├── getSubstringIndex.js │ ├── getSubstringIndex.spec.js │ ├── getSuggestionHtmlId.js │ ├── getSuggestionHtmlId.spec.js │ ├── index.js │ ├── isIE.js │ ├── isNumber.js │ ├── isNumber.spec.js │ ├── isPlainObject.js │ ├── isPlainObject.spec.js │ ├── iterateMentionsMarkup.js │ ├── iterateMentionsMarkup.spec.js │ ├── keys.js │ ├── keys.spec.js │ ├── makeMentionsMarkup.js │ ├── mapPlainTextIndex.js │ ├── mapPlainTextIndex.spec.js │ ├── markupToRegex.js │ ├── markupToRegex.spec.js │ ├── merge.js │ ├── merge.spec.js │ ├── mergeDeep.js │ ├── omit.js │ ├── omit.spec.js │ ├── placeholders.js │ ├── readConfigFromChildren.js │ ├── spliceString.js │ └── spliceString.spec.js ├── tests.webpack.js └── yarn.lock /.babelrc.js: -------------------------------------------------------------------------------- 1 | const { NODE_ENV } = process.env 2 | 3 | module.exports = { 4 | presets: [ 5 | [ 6 | '@babel/env', 7 | { 8 | modules: NODE_ENV === 'test' ? 'auto' : false, 9 | }, 10 | ], 11 | '@babel/react', 12 | '@babel/preset-flow', 13 | ], 14 | comments: true, 15 | plugins: [ 16 | '@babel/transform-runtime', 17 | '@babel/plugin-transform-flow-strip-types', 18 | '@babel/plugin-proposal-object-rest-spread', 19 | '@babel/plugin-proposal-export-namespace-from', 20 | '@babel/plugin-proposal-class-properties', 21 | ], 22 | } 23 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "public", 8 | "baseBranch": "master", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "react-app" 3 | } 4 | -------------------------------------------------------------------------------- /.github/codeql/codeql-config.yml: -------------------------------------------------------------------------------- 1 | paths-ignore: 2 | - '**/*.min.js' 3 | - build/ 4 | - dist/ 5 | - packages/**/dist 6 | - '**/*.readonly.js' 7 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master", "codeQlAct"] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "master" ,"codeQlAct"] 20 | schedule: 21 | - cron: '45 7 * * 0' #At 07:45 on Sunday. 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Use only 'java' to analyze code written in Java, Kotlin or both 38 | # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both 39 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 40 | 41 | steps: 42 | - name: Checkout repository 43 | uses: actions/checkout@v3 44 | 45 | # Initializes the CodeQL tools for scanning. 46 | - name: Initialize CodeQL 47 | uses: github/codeql-action/init@v2 48 | with: 49 | queries: security-extended 50 | config-file: ./.github/codeql/codeql-config.yml 51 | languages: ${{ matrix.language }} 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v2 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 60 | 61 | # If the Autobuild fails above, remove it and uncomment the following three lines. 62 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 63 | 64 | # - run: | 65 | # echo "Run, Build Application using script" 66 | # ./location_of_script_within_repo/buildscript.sh 67 | 68 | - name: Perform CodeQL Analysis 69 | uses: github/codeql-action/analyze@v2 70 | with: 71 | category: "/language:${{matrix.language}}" 72 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | concurrency: ${{ github.workflow }}-${{ github.ref }} 9 | 10 | jobs: 11 | release: 12 | name: Release 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout Repo 16 | uses: actions/checkout@v2 17 | 18 | - name: Setup Node.js 12.x 19 | uses: actions/setup-node@v2 20 | with: 21 | node-version: 12.x 22 | 23 | - name: Install Dependencies 24 | run: yarn 25 | 26 | - name: Create Release Pull Request or Publish to npm 27 | id: changesets 28 | uses: changesets/action@v1 29 | with: 30 | # This expects you to have a script called release which does a build for your packages and calls changeset publish 31 | publish: yarn release 32 | env: 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 35 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: push 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - name: Install modules 9 | run: yarn --frozen-lockfile 10 | - name: Lint 11 | run: yarn lint 12 | - name: Run tests 13 | run: yarn test 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | 3 | /reports 4 | /coverage 5 | /demo/dist 6 | /dist 7 | /demo/build 8 | 9 | npm-debug.log* 10 | 11 | *.log 12 | 13 | .DS_Store -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | gh-pages 3 | src 4 | test 5 | .gitignore 6 | .babelrc 7 | .travis.yml 8 | Gruntfile.js 9 | react-mentions.sublime-project 10 | .grunt -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json -------------------------------------------------------------------------------- /.reuse/dep5: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: BPMN-Sol 3 | Upstream-Contact: <> 4 | Source: 5 | Disclaimer: The code in this project may include calls to APIs ("API Calls") of 6 | SAP or third-party products or services developed outside of this project 7 | ("External Products"). 8 | "APIs" means application programming interfaces, as well as their respective 9 | specifications and implementing code that allows software to communicate with 10 | other software. 11 | API Calls to External Products are not licensed under the open source license 12 | that governs this project. The use of such API Calls and related External 13 | Products are subject to applicable additional agreements with the relevant 14 | provider of the External Products. In no event shall the open source license 15 | that governs this project grant any rights in or to any External Products,or 16 | alter, expand or supersede any terms of the applicable additional agreements. 17 | If you have a valid license agreement with SAP for the use of a particular SAP 18 | External Product, then you may make use of any API Calls included in this 19 | project's code for that SAP External Product, subject to the terms of such 20 | license agreement. If you do not have a valid license agreement for the use of 21 | a particular SAP External Product, then you may only make use of any API Calls 22 | in this project for that SAP External Product for your internal, non-productive 23 | and non-commercial test and evaluation of such API Calls. Nothing herein grants 24 | you any rights to use or access any SAP External Product, or provide any third 25 | parties the right to use of access any SAP External Product, through API Calls. 26 | 27 | Files: * 28 | Copyright: 2023 SAP SE or an SAP affiliate company and BPMN-Sol contributors 29 | License: Apache-2.0 -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "javascript.validate.enable": false, 3 | "editor.tabSize": 2, 4 | "search.exclude": { 5 | "**/lib": true 6 | }, 7 | "prettier.semi": false, 8 | "prettier.singleQuote": true, 9 | "prettier.trailingComma": "es5" 10 | } 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # react-mentions 2 | 3 | ## 4.5.0 4 | 5 | ### Minor Changes 6 | 7 | - 3a5036d: Allow the use of a custom input component 8 | 9 | ## 4.4.10 10 | 11 | ### Patch Changes 12 | 13 | - c9fd8ca: Remove autofocus from textarea by default 14 | - 32d9728: Fix suggestions not showing while composing 15 | - 4ef52dd: Fixed native undo/redo in case the input was not focused before the operation 16 | 17 | ## 4.4.9 18 | 19 | ### Patch Changes 20 | 21 | - 0e26027: Fix double-paste bug 22 | 23 | ## 4.4.8 24 | 25 | ### Patch Changes 26 | 27 | - ad43016: Typing fix in SuggestionsOverlay.js 28 | - e13731f: Fix package.json properties for release 29 | - 3f40576: Fixed the suggestions container that was not aligned with the caret position 30 | - db2d91a: Fix cursor jumping to the end of the textfield when pasting and using React 18 31 | - 1eef7df: Fix scroll into view automatically 32 | - a69db87: Custom container scrolling fixed, now works like other containers 33 | 34 | ## 4.4.7 35 | 36 | ### Patch Changes 37 | 38 | - 834240e: SuggestionsOverlay.js refactored to functional component 39 | - f8e5793: Highlighter.js converted to functional component 40 | 41 | ## 4.4.6 42 | 43 | ### Patch Changes 44 | 45 | - 959625b: Suggestions.js refactored to functional component 46 | 47 | ## 4.4.5 48 | 49 | ### Patch Changes 50 | 51 | - f40cff2: Fix #507 for forceSuggestionsAboveCursor when suggestionsPortalHost is not being used 52 | 53 | ## 4.4.4 54 | 55 | ### Patch Changes 56 | 57 | - 748d38a: fix npm publishing 58 | 59 | ## 4.4.3 60 | 61 | ### Patch Changes 62 | 63 | - e7f35ab: fix npm publishing 64 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@signavio.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for your interest in contributing to React-Mentions! 4 | This project is made possible by contributors like you, and we welcome any contributions to the code-base and the documentation. 5 | 6 | ## Environment 7 | 8 | - Ensure you have the latest version of Node and Yarn. 9 | - Run `yarn` to install all needed dev dependencies. 10 | 11 | ## Making Changes 12 | 13 | Pull requests are encouraged. If you want to add a feature or fix a bug: 14 | 15 | 1. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) and [clone](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) the [repository](https://github.com/signavio/react-mentions) 16 | 2. [Create a separate branch](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/managing-branches) for your changes 17 | 3. Make your changes, and ensure that it is formatted by [Prettier](https://prettier.io) 18 | 4. Write tests that validate your change and/or fix. 19 | 5. Run `yarn build` and then run tests with `yarn test` 20 | 6. If coding a new feature, please add the examples to the example app (`/demo/src/examples`) and add the docs to the `README.md` file. 21 | 7. Create a changeset by running `yarn changeset`. [More info](https://github.com/atlassian/changesets). 22 | 8. Push your branch and open a PR 🚀 23 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Steps to reproduce:** 2 | 3 | 1. 4 | 2. 5 | 3. 6 | 4. 7 | 5. 8 | 9 | **Expected behaviour:** 10 | 11 | **Observed behaviour:** 12 | 13 | **Workaround:** 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | Copyright (c) 2018, Signavio GmbH 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name Effektif nor the names of its contributors may be used to 17 | endorse or promote products derived from this software without specific 18 | prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /LICENSES/Apache-2.0.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 10 | 11 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 12 | 13 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 14 | 15 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 16 | 17 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 18 | 19 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 20 | 21 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 22 | 23 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 24 | 25 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 26 | 27 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 28 | 29 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 30 | 31 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 32 | 33 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 34 | 35 | (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and 36 | 37 | (b) You must cause any modified files to carry prominent notices stating that You changed the files; and 38 | 39 | (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 40 | 41 | (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 42 | 43 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 44 | 45 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 46 | 47 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 48 | 49 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 50 | 51 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 52 | 53 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 54 | 55 | END OF TERMS AND CONDITIONS 56 | 57 | APPENDIX: How to apply the Apache License to your work. 58 | 59 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 60 | 61 | Copyright [yyyy] [name of copyright owner] 62 | 63 | Licensed under the Apache License, Version 2.0 (the "License"); 64 | you may not use this file except in compliance with the License. 65 | You may obtain a copy of the License at 66 | 67 | http://www.apache.org/licenses/LICENSE-2.0 68 | 69 | Unless required by applicable law or agreed to in writing, software 70 | distributed under the License is distributed on an "AS IS" BASIS, 71 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 72 | See the License for the specific language governing permissions and 73 | limitations under the License. 74 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes #ABC 2 | 3 | What did you change (functionally and technically)? 4 | 5 | **Checklist** (remove this list before you submit the PR) 6 | * Are there tests for the new code? 7 | * Does the code comply to our code conventions? 8 | * Does the PR resolve the whole issue? 9 | 10 | **Additional review hints** (remove this list before you submit the PR) 11 | * Besides the code review, what should the reviewer test? 12 | * Are there any edge cases? 13 | * Do you have any test files or test set-up? 14 | * Could your changes cause side effects elsewhere in the code base? 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [React Mentions](https://react-mentions.vercel.app) 2 | [![REUSE status](https://api.reuse.software/badge/github.com/signavio/react-mentions)](https://api.reuse.software/info/github.com/signavio/react-mentions) 3 | 4 | A React component that let's you mention people in a textarea like you are used to on Facebook or Twitter. 5 | 6 | Used in production at [Signavio](https://signavio.com), [State](https://state.com), [Snips](https://snips.ai), [Swat.io](https://swat.io), [GotDone](https://www.gotdone.me), [Volinspire](https://volinspire.com), [Marvin](https://amazingmarvin.com), [Timely](https://timelyapp.com), [GuideFitter](https://www.guidefitter.com/), [Evite](https://www.evite.com/), [Publer](https://publer.me/), [Kontentino](https://www.kontentino.com/), [Wix.com](https://wix.com), [Highlight](https://highlight.run/) and [you?](https://github.com/signavio/react-mentions/edit/master/README.md) 7 | 8 | ## Getting started 9 | 10 | Install the _react-mentions_ package via npm: 11 | 12 | ``` 13 | npm install react-mentions --save 14 | ``` 15 | 16 | Or yarn: 17 | 18 | ``` 19 | yarn add react-mentions 20 | ``` 21 | 22 | The package exports two React components for rendering the mentions textarea: 23 | 24 | ```javascript 25 | import { MentionsInput, Mention } from 'react-mentions' 26 | ``` 27 | 28 | `MentionsInput` is the main component rendering the textarea control. It takes one or multiple `Mention` components as its children. Each `Mention` component represents a data source for a specific class of mentionable objects, such as users, template variables, issues, etc. 29 | 30 | Example: 31 | 32 | ```jsx 33 | 34 | 39 | 44 | 45 | ``` 46 | 47 | You can find more examples here: [demo/src/examples](https://github.com/signavio/react-mentions/tree/master/demo/src/examples) 48 | 49 | ## Configuration 50 | 51 | The `MentionsInput` supports the following props for configuring the widget: 52 | 53 | | Prop name | Type | Default value | Description | 54 | | --------------------------- | ------------------------------------------------------- | -------------- | -------------------------------------------------------------------------------------- | 55 | | value | string | `''` | The value containing markup for mentions | 56 | | onChange | function (event, newValue, newPlainTextValue, mentions) | empty function | A callback that is invoked when the user changes the value in the mentions input | 57 | | onKeyDown | function (event) | empty function | A callback that is invoked when the user presses a key in the mentions input | 58 | | singleLine | boolean | `false` | Renders a single line text input instead of a textarea, if set to `true` | 59 | | onBlur | function (event, clickedSuggestion) | empty function | Passes `true` as second argument if the blur was caused by a mousedown on a suggestion | 60 | | allowSpaceInQuery | boolean | false | Keep suggestions open even if the user separates keywords with spaces. | 61 | | suggestionsPortalHost | DOM Element | undefined | Render suggestions into the DOM in the supplied host element. | 62 | | inputRef | React ref | undefined | Accepts a React ref to forward to the underlying input element | 63 | | allowSuggestionsAboveCursor | boolean | false | Renders the SuggestionList above the cursor if there is not enough space below | 64 | | forceSuggestionsAboveCursor | boolean | false | Forces the SuggestionList to be rendered above the cursor | 65 | | a11ySuggestionsListLabel | string | `''` | This label would be exposed to screen readers when suggestion popup appears | 66 | | customSuggestionsContainer | function(children) | empty function | Allows customizing the container of the suggestions | 67 | | inputComponent | React component | undefined | Allows the use of a custom input component component | 68 | 69 | Each data source is configured using a `Mention` component, which has the following props: 70 | 71 | | Prop name | Type | Default value | Description | 72 | | ---------------- | ------------------------------------------------------------ | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | 73 | | trigger | regexp or string | `'@'` | Defines the char sequence upon which to trigger querying the data source | 74 | | data | array or function (search, callback) | `null` | An array of the mentionable data entries (objects with `id` & `display` keys, or a filtering function that returns an array based on a query parameter | 75 | | renderSuggestion | function (entry, search, highlightedDisplay, index, focused) | `null` | Allows customizing how mention suggestions are rendered (optional) | 76 | | markup | string | `'@[__display__](__id__)'` | A template string for the markup to use for mentions | 77 | | displayTransform | function (id, display) | returns `display` | Accepts a function for customizing the string that is displayed for a mention | 78 | | regex | RegExp | automatically derived from `markup` pattern | Allows providing a custom regular expression for parsing your markup and extracting the placeholder interpolations (optional) | | 79 | | onAdd | function (id, display, startPos, endPos) | empty function | Callback invoked when a suggestion has been added (optional) | 80 | | appendSpaceOnAdd | boolean | `false` | Append a space when a suggestion has been added (optional) | 81 | 82 | If a function is passed as the `data` prop, that function will be called with the current search query as first, and a callback function as second argument. The callback can be used to provide results asynchronously, e.g., after fetch requests. (It can even be called multiple times to update the list of suggestions.) 83 | 84 | ## Styling 85 | 86 | _react-mentions_ supports css, css modules, and inline styles. It is shipped with only some essential inline style definitions and without any css. Some example inline styles demonstrating how to customize the appearance of the `MentionsInput` can be found at [demo/src/examples/defaultStyle.js](https://github.com/signavio/react-mentions/blob/master/demo/src/examples/defaultStyle.js). 87 | 88 | If you want to use css, simply assign a `className` prop to `MentionsInput`. All DOM nodes rendered by the component will then receive class name attributes that are derived from the base class name you provided. 89 | 90 | If you want to avoid global class names and use css modules instead, you can provide the automatically generated class names as `classNames` to the `MentionsInput`. See [demo/src/examples/CssModules.js](https://github.com/signavio/react-mentions/blob/master/demo/src/examples/CssModules.js) for an example of using _react-mentions_ with css modules. 91 | 92 | You can also assign `className` and `style` props to the `Mention` elements to define how to highlight the mentioned words. 93 | 94 | ## Testing 95 | 96 | Due to react-mentions' internal cursor tracking it is not good enough to simulate the editing of the textarea value using `ReactTestUtils.Simulate.change`. 97 | We recommend using [@testing-library/user-event](https://github.com/testing-library/user-event) for a realistic simulation of events as they would happen in the browser as the user interacts the textarea. 98 | 99 | --- 100 | 101 | If you want to contribute, first of all: thank you ❤️. 102 | Please check [CONTRIBUTING.md](/CONTRIBUTING.md) and/or create an issue. 103 | -------------------------------------------------------------------------------- /demo/src/examples/Advanced.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { compose, withHandlers } from 'recompose' 3 | 4 | import { MentionsInput, Mention } from '../../../src' 5 | 6 | import { provideExampleValue } from './higher-order' 7 | 8 | import defaultStyle from './defaultStyle' 9 | import defaultMentionStyle from './defaultMentionStyle' 10 | 11 | import { merge } from '../../../src/utils' 12 | 13 | const style = merge({}, defaultStyle, { 14 | suggestions: { 15 | list: { 16 | maxHeight: 100, 17 | overflow: 'auto', 18 | position: 'absolute', 19 | bottom: 14, 20 | }, 21 | }, 22 | }) 23 | 24 | function Advanced({ value, data, onChange, onBlur, onAdd }) { 25 | let inputEl = React.createRef() 26 | return ( 27 |
28 |

Advanced options

29 | 30 | 38 | `<-- ${id} -->`} 41 | data={data} 42 | onAdd={onAdd} 43 | style={defaultMentionStyle} 44 | /> 45 | 46 | 47 | 54 |
55 | ) 56 | } 57 | 58 | export default compose( 59 | provideExampleValue('Hi {{johndoe}}!'), 60 | withHandlers({ 61 | onBlur: () => (ev, clickedOnSuggestion) => { 62 | if (!clickedOnSuggestion) { 63 | console.log('finished editing') 64 | } 65 | }, 66 | }) 67 | )(Advanced) 68 | -------------------------------------------------------------------------------- /demo/src/examples/AsyncGithubUserMentions.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import { MentionsInput, Mention } from '../../../src' 4 | 5 | import { provideExampleValue } from './higher-order' 6 | 7 | import defaultStyle from './defaultStyle' 8 | import defaultMentionStyle from './defaultMentionStyle' 9 | 10 | function fetchUsers(query, callback) { 11 | if (!query) return 12 | fetch(`https://api.github.com/search/users?q=${query}`, { json: true }) 13 | .then(res => res.json()) 14 | 15 | // Transform the users to what react-mentions expects 16 | .then(res => 17 | res.items.map(user => ({ display: user.login, id: user.login })) 18 | ) 19 | .then(callback) 20 | } 21 | 22 | function AsyncGithubUserMentions({ value, data, onChange }) { 23 | return ( 24 |
25 |

Async Github user mentions

26 | 27 | 34 | `@${login}`} 36 | trigger="@" 37 | data={fetchUsers} 38 | style={defaultMentionStyle} 39 | /> 40 | 41 |
42 | ) 43 | } 44 | 45 | const asExample = provideExampleValue('') 46 | 47 | export default asExample(AsyncGithubUserMentions) 48 | -------------------------------------------------------------------------------- /demo/src/examples/BottomGuard.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Mention, MentionsInput } from '../../../src' 3 | 4 | import { provideExampleValue } from './higher-order' 5 | import defaultStyle from './defaultStyle' 6 | import defaultMentionStyle from './defaultMentionStyle' 7 | let container 8 | 9 | function BottomGuard({ value, data, onChange, onAdd }) { 10 | return ( 11 |
{ 17 | container = el 18 | }} 19 | > 20 |

Bottom guard example

21 |

22 | Note that the bottom input will open the suggestions list above the 23 | cursor. 24 | Also, the middle one will render its suggestions always on top, 25 | even if it has enough space below. 26 |

27 |
37 | 46 | 47 | 48 |
49 |
50 |
51 |
52 |
53 | 61 | 62 | 63 |
64 |
65 |
66 |
67 | 76 | 77 | 78 |
79 |
80 | ) 81 | } 82 | 83 | const asExample = provideExampleValue('') 84 | 85 | export default asExample(BottomGuard) 86 | -------------------------------------------------------------------------------- /demo/src/examples/CssModules.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import { MentionsInput, Mention } from '../../../src' 4 | 5 | import { provideExampleValue } from './higher-order' 6 | 7 | import classNames from './example.module.css' 8 | 9 | function CssModules({ value, data, onChange }) { 10 | return ( 11 |
12 |

Styling with css modules

13 | 14 | 21 | 22 | 23 |
24 | ) 25 | } 26 | 27 | export default provideExampleValue('Hi @[John Doe](johndoe)')(CssModules) 28 | -------------------------------------------------------------------------------- /demo/src/examples/CustomInputComponent.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import { Mention, MentionsInput } from '../../../src' 4 | 5 | import { provideExampleValue } from './higher-order' 6 | import defaultStyle from './defaultStyle' 7 | import defaultMentionStyle from './defaultMentionStyle' 8 | 9 | // eslint-disable-next-line no-unused-vars 10 | import classNames from './example.module.css' // uses global css selector 11 | 12 | const CustomInput = React.forwardRef((props, ref) => { 13 | return