{"id":19219193,"url":"https://github.com/chassis/keyhandler","last_synced_at":"2026-03-16T12:03:15.765Z","repository":{"id":35103307,"uuid":"207113802","full_name":"Chassis/keyhandler","owner":"Chassis","description":"Handle keyboard shortcuts in your React components, and automatically show hints to users.","archived":false,"fork":false,"pushed_at":"2022-12-11T04:50:36.000Z","size":2246,"stargazers_count":3,"open_issues_count":19,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T05:02:25.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://chassis.github.io/keyhandler/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Chassis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-08T13:05:49.000Z","updated_at":"2020-06-07T07:15:40.000Z","dependencies_parsed_at":"2023-01-15T14:00:52.681Z","dependency_job_id":null,"html_url":"https://github.com/Chassis/keyhandler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chassis%2Fkeyhandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chassis%2Fkeyhandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chassis%2Fkeyhandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chassis%2Fkeyhandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chassis","download_url":"https://codeload.github.com/Chassis/keyhandler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249766005,"owners_count":21322519,"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-11-09T14:29:54.285Z","updated_at":"2026-03-16T12:03:15.739Z","avatar_url":"https://github.com/Chassis.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keyhandler\n\nHandle keyboard shortcuts in your React components, and automatically show hints to users.\n\n\u003cimg alt=\"Hint text displayed over component\" src=\"https://user-images.githubusercontent.com/21655/64488716-ded9c900-d242-11e9-8c5e-4b9e50e21d6f.png\" /\u003e\n\n**[View the demo →](https://chassis.github.io/keyhandler/)**\n\n[![NPM](https://img.shields.io/npm/v/@chassis-wp/keyhandler.svg)](https://www.npmjs.com/package/@chassis-wp/keyhandler)\n\n\n## Install\n\n```bash\n# With yarn:\nyarn add @chassis-wp/keyhandler\n\n# With npm:\nnpm install --save @chassis-wp/keyhandler\n```\n\n\n## Usage\n\nTo use Keyhandler, first render the Keyhandler provider at the top-level of your tree. This provider should be rendered above any Keyhandler components.\n\n```jsx\nimport { Provider } from '@chassis-wp/keyhandler';\n\nReactDOM.render(\n\t\u003cProvider\u003e\n\t\t\u003cApp /\u003e\n\t\u003c/Provider\u003e,\n\tdocument.getElementById( 'root' )\n);\n```\n\nThen, wherever you want to register a keyboard shortcut, render a KeyHandler component.\n\n```jsx\nimport React from 'react';\n\nimport KeyHandler from '@chassis-wp/keyhandler';\n\nfunction SaveButton( props ) {\n\treturn (\n\t\t\u003cbutton\n\t\t\tclassName=\"SaveButton\"\n\t\t\ttype=\"button\"\n\t\t\tonClick={ props.onSave }\n\t\t\u003e\n\t\t\t\u003cKeyHandler\n\t\t\t\tshortcut=\"cmd+s\"\n\t\t\t\tonTrigger={ props.onSave }\n\t\t\t/\u003e\n\n\t\t\tSave\n\t\t\u003c/button\u003e\n\t);\n}\n```\n\n### Shortcuts\n\nThe shortcut prop specifies the combination of keyboard characters to press in order to trigger your callback.\n\nShortcuts are specified as a string, with optional modifiers separated by plus (`+`) characters. `cmd`, `ctrl`, and `shift` are supported as modifiers; `alt` is not supported due to inconsistent behaviour across platforms.\n\nSymbols are supported, but note that the `shift` modifier has no effect, as many keyboards place multiple symbols on the same physical key; instead, use the character directly (e.g. `?` instead of `shift+/`).\n\nThe following special keys are also supported:\n\n* `escape` (or `esc`)\n* `enter`\n* `delete`\n* `backspace`\n* `space`\n* `up`, `down`, `left`, `right`\n\nSequences are not currently supported.\n\n\n### Hints\n\nKeyhandler by default renders hints when the meta key (Cmd on macOS) is held.\n\nThe hint is rendered into the tree at the position of the KeyHandler component, positioned at the centre of the nearest positioning parent (i.e.  parent with `position: relative/absolute/etc`).\n\nTo disable this behaviour on a specific handler, set the `disableHint` prop to `true`:\n\n```jsx\n\u003cKey disableHint shortcut=\"cmd+k\" /\u003e\n```\n\nTo disable this behaviour globally, set the `disableHints` prop on the provider to `true`:\n```jsx\n\u003cShortcutProvider disableHints\u003e\n\t\u003cApp /\u003e\n\u003c/ShortcutProvider\u003e\n```\n\n\n## Licence\n\nThis code is licensed under the MIT license.\n\nCopyright (c) 2019-present Ryan McCue, Bronson Quick\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchassis%2Fkeyhandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchassis%2Fkeyhandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchassis%2Fkeyhandler/lists"}