{"id":13647426,"url":"https://github.com/mapbox/react-keybinding","last_synced_at":"2026-01-11T02:53:12.598Z","repository":{"id":27599080,"uuid":"31082475","full_name":"mapbox/react-keybinding","owner":"mapbox","description":"declarative and robust keybindings for react","archived":true,"fork":false,"pushed_at":"2018-05-15T20:26:02.000Z","size":40,"stargazers_count":93,"open_issues_count":3,"forks_count":20,"subscribers_count":121,"default_branch":"master","last_synced_at":"2025-04-10T07:45:36.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mapbox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-20T19:57:11.000Z","updated_at":"2023-01-28T08:37:19.000Z","dependencies_parsed_at":"2022-08-26T03:11:09.155Z","dependency_job_id":null,"html_url":"https://github.com/mapbox/react-keybinding","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Freact-keybinding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Freact-keybinding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Freact-keybinding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mapbox%2Freact-keybinding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mapbox","download_url":"https://codeload.github.com/mapbox/react-keybinding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249990998,"owners_count":21357182,"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":[],"created_at":"2024-08-02T01:03:33.367Z","updated_at":"2026-01-11T02:53:12.568Z","avatar_url":"https://github.com/mapbox.png","language":"JavaScript","readme":"# react-keybinding\n\n[![build status](https://secure.travis-ci.org/mapbox/react-keybinding.png)](http://travis-ci.org/mapbox/react-keybinding)\n\nDeclarative, lightweight, and robust keybindings mixin for React.\n\n* Straightforward `'⌘S'` string syntax for declaring bindings\n* Automatically binds \u0026 unbinds keybindings when components mount and unmount\n* Allows listing of all currently-active keybindings\n* Run a function when a keybinding is hit or pass an action\n  to the `keybinding` method of that component\n* Doesn't fire keybindings accidentally triggered in inputs,\n  select boxes, or textareas.\n* Optionally coerce platform specific keybindings (i.e. `'⌘S'` on Mac to `'^S'` on Windows)\n\n## Installation\n\nInstall with [npm](https://www.npmjs.com/) and use in your React\nprojects with either [browserify](http://browserify.org/) or\n[webpack](http://webpack.github.io/).\n\n```sh\n$ npm install react-keybinding\n```\n\n## Example\n\n```js\nvar React = require('react'),\n    Keybinding = require('../');\nvar HelloMessage = React.createClass({\n  mixins: [Keybinding],\n  keybindingsPlatformAgnostic: true,\n  keybindings: {\n    '⌘S': function(e) {\n      console.log('save!');\n      e.preventDefault();\n    },\n    '⌘C': 'COPY'\n  },\n  keybinding: function(event, action) {\n    // event is the browser event, action is 'COPY'\n    console.log(arguments);\n  },\n  render: function() {\n    return React.createElement(\"div\", null, \"Hello\");\n  }\n});\nReact.render(React.createElement(HelloMessage, {name: \"John\"}), document.body);\n```\n\nThere's a runnable example in the `./examples` directory: to run it,\n\n```sh\n$ npm install\n$ cd example\n$ npm install\n$ npm start\n```\n\nSee [tmcw/ditty](https://github.com/tmcw/ditty) for an example of\nreact-keybinding in an application.\n\n### API\n\nThis module exposes a single mixin called `Keybinding`.\n\nWhere you use this mixin on Components, it expects a property called\n`keybindings` of the format:\n\n```js\nkeybindings: {\n  // keys are strings: they can contain meta and shift symbols,\n  // numbers, strings, etc\n  '⌘S': function(e) {\n    // bindings can map to functions that they call directly\n  },\n  // or to constants that are passed to the component's\n  // 'keybinding' method.\n  '⌘C': 'COPY'\n}\n```\n\nPlatform agnostic keybindings will automatically listen for the `'Ctrl'`\nequivalent of `'Cmd'` keybindings, and vice-versa. To automatically coerce\nplatform specific keybindings, provide a property called\n`keybindingsPlatformAgnostic` of the format:\n\n```js\nkeybindingsPlatformAgnostic: true,\nkeybindings: { ... }\n```\n\nThe mixin provides a method for components called `.getAllKeybindings()`:\nthis yields an array of all `keybindings` properties on all active components.\n\n## [Syntax](SYNTAX.md)\n\nThe full [range of codes and modifiers supported is listed in SYNTAX.md](SYNTAX.md).\n\n## Tests\n\n```sh\n$ npm test\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapbox%2Freact-keybinding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapbox%2Freact-keybinding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapbox%2Freact-keybinding/lists"}