{"id":13394063,"url":"https://github.com/abinavseelan/react-input-trigger","last_synced_at":"2025-03-13T19:31:58.086Z","repository":{"id":44569458,"uuid":"123054071","full_name":"abinavseelan/react-input-trigger","owner":"abinavseelan","description":"React component for handling character triggers inside textareas and input fields. 🐼","archived":false,"fork":false,"pushed_at":"2023-03-01T20:23:28.000Z","size":1599,"stargazers_count":88,"open_issues_count":18,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-16T18:05:32.148Z","etag":null,"topics":["javascript","react","react-component"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abinavseelan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-02-27T01:23:40.000Z","updated_at":"2023-12-16T09:25:04.000Z","dependencies_parsed_at":"2024-01-13T17:11:16.518Z","dependency_job_id":"a22ef69d-b21f-40d9-a533-bacd629c16cc","html_url":"https://github.com/abinavseelan/react-input-trigger","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":0.1351351351351351,"last_synced_commit":"c2feaaa5275c7405a60133bd677b01d0aa445897"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abinavseelan%2Freact-input-trigger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abinavseelan%2Freact-input-trigger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abinavseelan%2Freact-input-trigger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abinavseelan%2Freact-input-trigger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abinavseelan","download_url":"https://codeload.github.com/abinavseelan/react-input-trigger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243112187,"owners_count":20238181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","react","react-component"],"created_at":"2024-07-30T17:01:07.691Z","updated_at":"2025-03-13T19:31:57.676Z","avatar_url":"https://github.com/abinavseelan.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# React Input Trigger\n\n[![npm][npm-badge]][npm-url]\n[![license][license-badge]][license-url]\n[![downloads][downloads-badge]][downloads-url]\n[![size][size-badge]][size-url]\n\n[![deps][deps-badge]][deps-url]\n[![peer-deps][peer-deps-badge]][peer-deps-url]\n\n\u003e React component for handling character triggers inside textareas and input fields. 🐼\n\n## Description\n\nUseful for building applications that need Slack-like emoji suggestions (triggered by typing `:`) or Github-like user mentions (triggered by typing `@`).\n\nThe component provides the following hooks:\n\n* `onStart`: whenever the trigger is first activated (eg. when `@` is first typed).\n* `onType`: when something is being typed after it's been triggered.\n* `onCancel`: when the trigger is canceled.\n\nThe hooks pass some meta-data such as the cursor position and/or the text that has been typed since the trigger has been activated.\n\n![reactinputtrigger](https://user-images.githubusercontent.com/6417910/36937827-0e615e4e-1f3f-11e8-9623-c4141bda3d2e.gif)\n\n## Demo\n\nA live demo of this component can be found [here](https://abinavseelan.com/react-input-trigger).\n\nA detailed guide on using this component to build a Github-style user mentions component [can be found on CampVanilla](https://blog.campvanilla.com/reactjs-input-trigger-github-twitter-mentions-8ad1d878110d).\n\n## Usage\n\n### Getting Started\n\n* Install the component\n\n```bash\n$ npm install react-input-trigger\n```\n\n* Import the component from the package.\n\n```js\nimport InputTrigger from 'react-input-trigger';\n```\n\n* Wrap your existing `\u003ctextarea /\u003e` or `\u003cinput /\u003e` element with `\u003cInputTrigger /\u003e`\n\n```jsx\n\u003cInputTrigger\u003e\n  \u003ctextarea /\u003e\n\u003c/InputTrigger\u003e\n```\n\n---\n\nOr get it in the browser directly via [unpkg](https://unpkg.com/react-input-trigger@latest/build/lib/react-input-trigger.js):\n\n```html\n\u003cscript\n  src=\"https://unpkg.com/react-input-trigger@latest/build/lib/react-input-trigger.js\"\n  type=\"text/javascript\"\u003e\n\u003c/script\u003e\n```\n\n## Component Props\n\n`\u003cInputTrigger\u003e` can take in the following props:\n\n### trigger\n\nThis prop takes an object that defines the trigger. The object can have the following properties\n\n* `keyCode`: This is the character code that will fire the trigger.\n* `shiftKey`: (Optional) Set this to `true` if you need the shift key to be pressed along with the `keyCode` to start the trigger. Ignore this property if it's not required.\n* `ctrlKey`: (Optional) Set this to `true` if you need the ctrl key to be pressed along with the `keyCode` to start the trigger. Ignore this property if it's not required.\n* `metaKey`: (Optional) Set this to `true` if you need the cmd key to be pressed along with the `keyCode` to start the trigger. Ignore this property if it's not required.\n\n```jsx\n\u003cInputTrigger\n  trigger={{\n    keyCode: 50,\n    shiftKey: true,\n  }}\n\u003e\n```\n\n### onStart\n\nThis prop takes a function that will fire whenever trigger is activated. The function is passed some meta information about the cursor's position that you can use.\n\n```jsx\n\u003cInputTrigger\n  trigger={{\n    keyCode: 50,\n    shiftKey: true,\n  }}\n  onStart={(obj) =\u003e { console.log(obj); }}\n\u003e\n```\n\nThe parameter `obj` contains the following meta information\n\n```js\n{\n  \"hookType\": \"start\",\n  \"cursor\": {\n    \"selectionStart\",\n    \"selectionEnd\",\n    \"top\",\n    \"left\",\n    \"height\"\n  }\n}\n```\n\n### onCancel\n\nThis prop takes a function that will fire everytime the user presses backspace and removes the trigger from the input section. The function is passed some meta information about the cursor's position that you can use.\n\n```jsx\n\u003cInputTrigger\n  trigger={{\n    keyCode: 50,\n    shiftKey: true,\n  }}\n  onCancel={(obj) =\u003e { console.log(obj); }}\n\u003e\n```\n\nThe parameter `obj` contains the following meta information\n\n```js\n{\n  \"hookType\": \"cancel\",\n  \"cursor\": {\n    \"selectionStart\",\n    \"selectionEnd\",\n    \"top\",\n    \"left\",\n    \"height\"\n  }\n}\n```\n\n### onType\n\nThis prop takes a function that will trigger everytime the user continues typing after starting the trigger. The function is passed some meta information about the cursor's position, as well as the text that the user has typed after triggering that you can use.\n\n```jsx\n\u003cInputTrigger\n  trigger={{\n    keyCode: 50,\n    shiftKey: true,\n  }}\n  onType={(obj) =\u003e { console.log(obj); }}\n\u003e\n```\n\nThe parameter `obj` contains the following meta information\n\n```js\n{\n  \"hookType\": \"typing\",\n  \"cursor\": {\n    \"selectionStart\",\n    \"selectionEnd\",\n    \"top\",\n    \"left\",\n    \"height\"\n  },\n  \"text\"\n}\n```\n\n### endTrigger\n\nThis prop takes a function that returns a function that you need to keep in your parent component. This returned method needs to be called manually by the parent component whenever you are done using the trigger and want to end the trigger.\n\n```jsx\n\u003cInputTrigger\n  endTrigger={\n    endTriggerHandler =\u003e {\n      this.endTriggerHandler = endTriggerHandler;\n\n      /*\n        Now you can call `this.endTriggerHandler`\n        anywhere inside the parent component\n        whenever you want to stop the trigger!\n      */\n    }\n  }\n\u003e\n```\n\n## Contributing\n\nWant to fix something, add a new feature or raise an issue? Please read the [contributing guide](https://github.com/abinavseelan/react-input-trigger/blob/master/CONTRIBUTING.md) to get started. :smile:\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\n\u003c!-- prettier-ignore --\u003e\n| [\u003cimg src=\"https://avatars2.githubusercontent.com/u/6417910?s=200\u0026v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAbinav Seelan\u003c/b\u003e\u003c/sub\u003e](https://abinavseelan.com)\u003cbr /\u003e[💻](https://github.com/abinavseelan/react-input-trigger/commits?author=abinavseelan \"Code\") [📖](https://github.com/abinavseelan/react-input-trigger/commits?author=abinavseelan \"Documentation\") | [\u003cimg src=\"https://avatars0.githubusercontent.com/u/6426069?s=200\u0026v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAditi Mohanty\u003c/b\u003e\u003c/sub\u003e](https://github.com/rheaditi)\u003cbr /\u003e[💻](https://github.com/abinavseelan/react-input-trigger/commits?author=rheaditi \"Code\") [📖](https://github.com/abinavseelan/react-input-trigger/commits?author=rheaditi \"Documentation\") | [\u003cimg src=\"https://avatars2.githubusercontent.com/u/6963212?s=200\u0026v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAdam Goldman\u003c/b\u003e\u003c/sub\u003e](https://github.com/goldylucks)\u003cbr /\u003e[💻](https://github.com/abinavseelan/react-input-trigger/commits?author=goldylucks \"Code\") |\n| :---: | :---: | :---: |\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n\n[npm-badge]: https://img.shields.io/npm/v/react-input-trigger.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/react-input-trigger\n[license-badge]: https://img.shields.io/npm/l/react-input-trigger.svg?style=flat-square\u0026color=blue\n[license-url]: https://github.com/abinavseelan/react-input-trigger/blob/master/LICENSE\n[downloads-badge]: https://img.shields.io/npm/dt/react-input-trigger.svg?style=flat-square\u0026color=blue\n[downloads-url]: https://www.npmjs.com/package/react-input-trigger\n[deps-badge]: https://img.shields.io/david/abinavseelan/react-input-trigger.svg?style=flat-square\n[deps-url]: https://david-dm.org/abinavseelan/react-input-trigger\n[peer-deps-badge]: https://img.shields.io/david/peer/abinavseelan/react-input-trigger.svg?style=flat-square\n[peer-deps-url]: https://david-dm.org/abinavseelan/react-input-trigger/peer-status\n[size-badge]: https://img.shields.io/bundlephobia/minzip/react-input-trigger.svg?style=flat-square\u0026label=gzipped\n[size-url]: https://bundlephobia.com/result?p=react-input-trigger\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabinavseelan%2Freact-input-trigger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabinavseelan%2Freact-input-trigger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabinavseelan%2Freact-input-trigger/lists"}